From dc3ed808a218a1d1a32fff5c33e811e3cf113abb Mon Sep 17 00:00:00 2001 From: Hoan Pham Date: Tue, 23 Jun 2015 16:33:15 +0700 Subject: [PATCH 1/2] fix NSDate support iOS 7 Because components.valueForComponent(component) is available from iOS 8 --- ExSwift/NSDate.swift | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ExSwift/NSDate.swift b/ExSwift/NSDate.swift index 50d758e..87b8f04 100644 --- a/ExSwift/NSDate.swift +++ b/ExSwift/NSDate.swift @@ -252,7 +252,30 @@ public extension NSDate { let calendar = NSCalendar.currentCalendar() let components = calendar.components(component, fromDate: self) - return components.valueForComponent(component) + if component & NSCalendarUnit.CalendarUnitYear != nil { + return components.year + } + if component & NSCalendarUnit.CalendarUnitMonth != nil { + return components.month + } + if component & NSCalendarUnit.CalendarUnitWeekday != nil { + return components.weekday + } + if component & NSCalendarUnit.CalendarUnitWeekOfMonth != nil { + return components.weekOfMonth + } + if component & NSCalendarUnit.CalendarUnitHour != nil { + return components.hour + } + if component & NSCalendarUnit.CalendarUnitMinute != nil { + return components.minute + } + if component & NSCalendarUnit.CalendarUnitSecond != nil { + return components.second + } + + + return 0 } } From bebcbb89f6693cd79bfedf67def559ded25ec89e Mon Sep 17 00:00:00 2001 From: Hoan Pham Date: Wed, 24 Jun 2015 02:29:23 +0700 Subject: [PATCH 2/2] fix iOS 7 NSDate support --- ExSwift/NSDate.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ExSwift/NSDate.swift b/ExSwift/NSDate.swift index 87b8f04..6c5a439 100644 --- a/ExSwift/NSDate.swift +++ b/ExSwift/NSDate.swift @@ -258,6 +258,9 @@ public extension NSDate { if component & NSCalendarUnit.CalendarUnitMonth != nil { return components.month } + if component & NSCalendarUnit.CalendarUnitDay != nil { + return components.day + } if component & NSCalendarUnit.CalendarUnitWeekday != nil { return components.weekday } @@ -274,7 +277,6 @@ public extension NSDate { return components.second } - return 0 } }