diff --git a/AFDateHelper.xcodeproj/project.pbxproj b/AFDateHelper.xcodeproj/project.pbxproj index 278170b..b86d229 100644 --- a/AFDateHelper.xcodeproj/project.pbxproj +++ b/AFDateHelper.xcodeproj/project.pbxproj @@ -223,7 +223,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "All Forces"; TargetAttributes = { 63B7E9B21CF6DCFE00E9D8EF = { @@ -232,9 +232,11 @@ 65889B6B1965051C0049740E = { CreatedOnToolsVersion = 6.0; DevelopmentTeam = ERA9S8SPNY; + LastSwiftMigration = 0800; }; CD1B22691CB62C8400992308 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; }; }; @@ -370,6 +372,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.allforces.AFDateHelperTVDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -390,12 +393,15 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -408,7 +414,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -431,18 +437,21 @@ CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -469,6 +478,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.allforces.AFDateHelperDemo; PRODUCT_NAME = AFDateHelper; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -487,6 +497,8 @@ METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.allforces.AFDateHelperDemo; PRODUCT_NAME = AFDateHelper; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -514,6 +526,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -542,6 +555,8 @@ PRODUCT_BUNDLE_IDENTIFIER = com.allforces.AFDateHelper; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; diff --git a/AFDateHelper.xcodeproj/xcshareddata/xcschemes/AFDateHelper.xcscheme b/AFDateHelper.xcodeproj/xcshareddata/xcschemes/AFDateHelper.xcscheme index fc5ef17..9694713 100644 --- a/AFDateHelper.xcodeproj/xcshareddata/xcschemes/AFDateHelper.xcscheme +++ b/AFDateHelper.xcodeproj/xcshareddata/xcschemes/AFDateHelper.xcscheme @@ -1,6 +1,6 @@ Double { return 60 } - private class func hourInSeconds() -> Double { return 3600 } - private class func dayInSeconds() -> Double { return 86400 } - private class func weekInSeconds() -> Double { return 604800 } - private class func yearInSeconds() -> Double { return 31556926 } + private static func minuteInSeconds() -> Double { return 60 } + private static func hourInSeconds() -> Double { return 3600 } + private static func dayInSeconds() -> Double { return 86400 } + private static func weekInSeconds() -> Double { return 604800 } + private static func yearInSeconds() -> Double { return 31556926 } // MARK: Components - private class func componentFlags() -> NSCalendarUnit { return [NSCalendarUnit.Year, NSCalendarUnit.Month, NSCalendarUnit.Day, NSCalendarUnit.WeekOfYear, NSCalendarUnit.Hour, NSCalendarUnit.Minute, NSCalendarUnit.Second, NSCalendarUnit.Weekday, NSCalendarUnit.WeekdayOrdinal, NSCalendarUnit.WeekOfYear] } + private static func componentFlags() -> Set { return [Calendar.Component.year, Calendar.Component.month, Calendar.Component.day, Calendar.Component.weekOfYear, Calendar.Component.hour, Calendar.Component.minute, Calendar.Component.second, Calendar.Component.weekday, Calendar.Component.weekdayOrdinal, Calendar.Component.weekOfYear] } - private class func components(fromDate fromDate: NSDate) -> NSDateComponents! { - return NSCalendar.currentCalendar().components(NSDate.componentFlags(), fromDate: fromDate) + private static func components(_ fromDate: Date) -> DateComponents! { + return Calendar.current.dateComponents(Date.componentFlags(), from: fromDate) } - private func components() -> NSDateComponents { - return NSDate.components(fromDate: self)! + private func components() -> DateComponents { + return Date.components(self)! } // MARK: Date From String @@ -81,7 +81,7 @@ public extension NSDate { - Returns A new date */ - convenience init(fromString string: String, format:DateFormat, timeZone: TimeZone = .Local) + init(fromString string: String, format:DateFormat, timeZone: TimeZone = .local) { if string.isEmpty { self.init() @@ -90,70 +90,70 @@ public extension NSDate { let string = string as NSString - let zone: NSTimeZone + let zone: Foundation.TimeZone switch timeZone { - case .Local: - zone = NSTimeZone.localTimeZone() - case .UTC: - zone = NSTimeZone(forSecondsFromGMT: 0) + case .local: + zone = Foundation.NSTimeZone.local + case .utc: + zone = Foundation.TimeZone(secondsFromGMT: 0)! } switch format { - case .DotNet: + case .dotNet: - let startIndex = string.rangeOfString("(").location + 1 - let endIndex = string.rangeOfString(")").location + let startIndex = string.range(of: "(").location + 1 + let endIndex = string.range(of: ")").location let range = NSRange(location: startIndex, length: endIndex-startIndex) - let milliseconds = (string.substringWithRange(range) as NSString).longLongValue - let interval = NSTimeInterval(milliseconds / 1000) + let milliseconds = (string.substring(with: range) as NSString).longLongValue + let interval = TimeInterval(milliseconds / 1000) self.init(timeIntervalSince1970: interval) - case .ISO8601(let isoFormat): + case .iso8601(let isoFormat): let dateFormat = (isoFormat != nil) ? isoFormat! : ISO8601Format(dateString: string as String) - let formatter = NSDate.formatter(format: dateFormat.rawValue) - formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") - formatter.timeZone = NSTimeZone.localTimeZone() + let formatter = Date.formatter(dateFormat.rawValue) + formatter.locale = Foundation.Locale(identifier: "en_US_POSIX") + formatter.timeZone = Foundation.NSTimeZone.local formatter.dateFormat = dateFormat.rawValue - if let date = formatter.dateFromString(string as String) { - self.init(timeInterval:0, sinceDate:date) + if let date = formatter.date(from: string as String) { + self.init(timeInterval:0, since:date) } else { self.init() } - case .RSS: + case .rss: var s = string if string.hasSuffix("Z") { - s = s.substringToIndex(s.length-1) + "GMT" + s = s.substring(to: s.length-1) + "GMT" } - let formatter = NSDate.formatter(format: RSSFormat) - if let date = formatter.dateFromString(string as String) { - self.init(timeInterval:0, sinceDate:date) + let formatter = Date.formatter(RSSFormat) + if let date = formatter.date(from: string as String) { + self.init(timeInterval:0, since:date) } else { self.init() } - case .AltRSS: + case .altRSS: var s = string if string.hasSuffix("Z") { - s = s.substringToIndex(s.length-1) + "GMT" + s = s.substring(to: s.length-1) + "GMT" } - let formatter = NSDate.formatter(format: AltRSSFormat) - if let date = formatter.dateFromString(string as String) { - self.init(timeInterval:0, sinceDate:date) + let formatter = Date.formatter(AltRSSFormat) + if let date = formatter.date(from: string as String) { + self.init(timeInterval:0, since:date) } else { self.init() } - case .Custom(let dateFormat): + case .custom(let dateFormat): - let formatter = NSDate.formatter(format: dateFormat, timeZone: zone) - if let date = formatter.dateFromString(string as String) { - self.init(timeInterval:0, sinceDate:date) + let formatter = Date.formatter(dateFormat, timeZone: zone) + if let date = formatter.date(from: string as String) { + self.init(timeInterval:0, since:date) } else { self.init() } @@ -169,11 +169,11 @@ public extension NSDate { - Parameter date: The Date to compare. */ - func isEqualToDateIgnoringTime(date: NSDate) -> Bool + func isEqualToDateIgnoringTime(_ date: Date) -> Bool { - let comp1 = NSDate.components(fromDate: self) - let comp2 = NSDate.components(fromDate: date) - return ((comp1.year == comp2.year) && (comp1.month == comp2.month) && (comp1.day == comp2.day)) + let comp1 = Date.components(self) + let comp2 = Date.components(date) + return ((comp1!.year == comp2!.year) && (comp1!.month == comp2!.month) && (comp1!.day == comp2!.day)) } /** @@ -181,7 +181,7 @@ public extension NSDate { */ func isToday() -> Bool { - return self.isEqualToDateIgnoringTime(NSDate()) + return self.isEqualToDateIgnoringTime(Date()) } /** @@ -189,7 +189,7 @@ public extension NSDate { */ func isTomorrow() -> Bool { - return self.isEqualToDateIgnoringTime(NSDate().dateByAddingDays(1)) + return self.isEqualToDateIgnoringTime(Date().dateByAddingDays(1)) } /** @@ -197,7 +197,7 @@ public extension NSDate { */ func isYesterday() -> Bool { - return self.isEqualToDateIgnoringTime(NSDate().dateBySubtractingDays(1)) + return self.isEqualToDateIgnoringTime(Date().dateBySubtractingDays(1)) } /** @@ -205,16 +205,16 @@ public extension NSDate { - Parameter date: The date to compare. */ - func isSameWeekAsDate(date: NSDate) -> Bool + func isSameWeekAsDate(_ date: Date) -> Bool { - let comp1 = NSDate.components(fromDate: self) - let comp2 = NSDate.components(fromDate: date) + let comp1 = Date.components(self) + let comp2 = Date.components(date) // Must be same week. 12/31 and 1/1 will both be week "1" if they are in the same week - if comp1.weekOfYear != comp2.weekOfYear { + if comp1?.weekOfYear != comp2?.weekOfYear { return false } // Must have a time interval under 1 week - return abs(self.timeIntervalSinceDate(date)) < NSDate.weekInSeconds() + return abs(self.timeIntervalSince(date)) < Date.weekInSeconds() } /** @@ -222,7 +222,7 @@ public extension NSDate { */ func isThisWeek() -> Bool { - return self.isSameWeekAsDate(NSDate()) + return self.isSameWeekAsDate(Date()) } /** @@ -230,8 +230,8 @@ public extension NSDate { */ func isNextWeek() -> Bool { - let interval: NSTimeInterval = NSDate().timeIntervalSinceReferenceDate + NSDate.weekInSeconds() - let date = NSDate(timeIntervalSinceReferenceDate: interval) + let interval: TimeInterval = Date().timeIntervalSinceReferenceDate + Date.weekInSeconds() + let date = Date(timeIntervalSinceReferenceDate: interval) return self.isSameWeekAsDate(date) } @@ -240,8 +240,8 @@ public extension NSDate { */ func isLastWeek() -> Bool { - let interval: NSTimeInterval = NSDate().timeIntervalSinceReferenceDate - NSDate.weekInSeconds() - let date = NSDate(timeIntervalSinceReferenceDate: interval) + let interval: TimeInterval = Date().timeIntervalSinceReferenceDate - Date.weekInSeconds() + let date = Date(timeIntervalSinceReferenceDate: interval) return self.isSameWeekAsDate(date) } @@ -250,11 +250,11 @@ public extension NSDate { - Parameter date: The date to compare. */ - func isSameYearAsDate(date: NSDate) -> Bool + func isSameYearAsDate(_ date: Date) -> Bool { - let comp1 = NSDate.components(fromDate: self) - let comp2 = NSDate.components(fromDate: date) - return comp1.year == comp2.year + let comp1 = Date.components(self) + let comp2 = Date.components(date) + return comp1!.year == comp2!.year } /** @@ -262,12 +262,12 @@ public extension NSDate { - Parameter date: The date to compare */ - func isSameMonthAsDate(date: NSDate) -> Bool + func isSameMonthAsDate(_ date: Date) -> Bool { - let comp1 = NSDate.components(fromDate: self) - let comp2 = NSDate.components(fromDate: date) + let comp1 = Date.components(self) + let comp2 = Date.components(date) - return comp1.year == comp2.year && comp1.month == comp2.month + return comp1!.year == comp2!.year && comp1!.month == comp2!.month } /** @@ -275,7 +275,7 @@ public extension NSDate { */ func isThisYear() -> Bool { - return self.isSameYearAsDate(NSDate()) + return self.isSameYearAsDate(Date()) } /** @@ -283,9 +283,9 @@ public extension NSDate { */ func isNextYear() -> Bool { - let comp1 = NSDate.components(fromDate: self) - let comp2 = NSDate.components(fromDate: NSDate()) - return (comp1.year == comp2.year + 1) + let comp1 = Date.components(self) + let comp2 = Date.components(Date()) + return (comp1!.year! == comp2!.year! + 1) } /** @@ -293,9 +293,9 @@ public extension NSDate { */ func isLastYear() -> Bool { - let comp1 = NSDate.components(fromDate: self) - let comp2 = NSDate.components(fromDate: NSDate()) - return (comp1.year == comp2.year - 1) + let comp1 = Date.components(self) + let comp2 = Date.components(Date()) + return (comp1!.year! == comp2!.year! - 1) } /** @@ -303,9 +303,9 @@ public extension NSDate { - Parameter date: The date to compare. */ - func isEarlierThanDate(date: NSDate) -> Bool + func isEarlierThanDate(_ date: Date) -> Bool { - return self.earlierDate(date) == self + return (self as NSDate).earlierDate(date) == self } /** @@ -313,9 +313,9 @@ public extension NSDate { - Parameter date: The date to compare. */ - func isLaterThanDate(date: NSDate) -> Bool + func isLaterThanDate(_ date: Date) -> Bool { - return self.laterDate(date) == self + return (self as NSDate).laterDate(date) == self } /** @@ -323,7 +323,7 @@ public extension NSDate { */ func isInFuture() -> Bool { - return self.isLaterThanDate(NSDate()) + return self.isLaterThanDate(Date()) } /** @@ -331,7 +331,7 @@ public extension NSDate { */ func isInPast() -> Bool { - return self.isEarlierThanDate(NSDate()) + return self.isEarlierThanDate(Date()) } @@ -343,11 +343,11 @@ public extension NSDate { - Parameter days: The number of months to add. - Returns A new date object. */ - func dateByAddingMonths(months: Int) -> NSDate + func dateByAddingMonths(_ months: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.month = months - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -356,11 +356,11 @@ public extension NSDate { - Parameter days: The number of months to substract. - Returns A new date object. */ - func dateBySubtractingMonths(months: Int) -> NSDate + func dateBySubtractingMonths(_ months: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.month = (months * -1) - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -369,11 +369,11 @@ public extension NSDate { - Parameter days: The number of weeks to add. - Returns A new date object. */ - func dateByAddingWeeks(weeks: Int) -> NSDate + func dateByAddingWeeks(_ weeks: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.day = 7 * weeks - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -382,11 +382,11 @@ public extension NSDate { - Parameter days: The number of weeks to substract. - Returns A new date object. */ - func dateBySubtractingWeeks(weeks: Int) -> NSDate + func dateBySubtractingWeeks(_ weeks: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.day = ((7 * weeks) * -1) - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -395,11 +395,11 @@ public extension NSDate { - Parameter days: The number of days to add. - Returns A new date object. */ - func dateByAddingDays(days: Int) -> NSDate + func dateByAddingDays(_ days: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.day = days - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -408,11 +408,11 @@ public extension NSDate { - Parameter days: The number of days to substract. - Returns A new date object. */ - func dateBySubtractingDays(days: Int) -> NSDate + func dateBySubtractingDays(_ days: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.day = (days * -1) - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -421,11 +421,11 @@ public extension NSDate { - Parameter days: The number of hours to add. - Returns A new date object. */ - func dateByAddingHours(hours: Int) -> NSDate + func dateByAddingHours(_ hours: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.hour = hours - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -434,11 +434,11 @@ public extension NSDate { - Parameter days: The number of hours to substract. - Returns A new date object. */ - func dateBySubtractingHours(hours: Int) -> NSDate + func dateBySubtractingHours(_ hours: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.hour = (hours * -1) - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -447,11 +447,11 @@ public extension NSDate { - Parameter days: The number of minutes to add. - Returns A new date object. */ - func dateByAddingMinutes(minutes: Int) -> NSDate + func dateByAddingMinutes(_ minutes: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.minute = minutes - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -460,11 +460,11 @@ public extension NSDate { - Parameter days: The number of minutes to add. - Returns A new date object. */ - func dateBySubtractingMinutes(minutes: Int) -> NSDate + func dateBySubtractingMinutes(_ minutes: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.minute = (minutes * -1) - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -473,11 +473,11 @@ public extension NSDate { - Parameter seconds: The number of seconds to add. - Returns A new date object. */ - func dateByAddingSeconds(seconds: Int) -> NSDate + func dateByAddingSeconds(_ seconds: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.second = seconds - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -486,11 +486,11 @@ public extension NSDate { - Parameter days: The number of seconds to substract. - Returns A new date object. */ - func dateBySubtractingSeconds(seconds: Int) -> NSDate + func dateBySubtractingSeconds(_ seconds: Int) -> Date { - let dateComp = NSDateComponents() + var dateComp = DateComponents() dateComp.second = (seconds * -1) - return NSCalendar.currentCalendar().dateByAddingComponents(dateComp, toDate: self, options: NSCalendarOptions(rawValue: 0))! + return Calendar.current.date(byAdding: dateComp, to: self)! } /** @@ -498,13 +498,13 @@ public extension NSDate { - Returns A new date object. */ - func dateAtStartOfDay() -> NSDate + func dateAtStartOfDay() -> Date { - let components = self.components() + var components = self.components() components.hour = 0 components.minute = 0 components.second = 0 - return NSCalendar.currentCalendar().dateFromComponents(components)! + return Calendar.current.date(from: components)! } /** @@ -512,13 +512,13 @@ public extension NSDate { - Returns A new date object. */ - func dateAtEndOfDay() -> NSDate + func dateAtEndOfDay() -> Date { - let components = self.components() + var components = self.components() components.hour = 23 components.minute = 59 components.second = 59 - return NSCalendar.currentCalendar().dateFromComponents(components)! + return Calendar.current.date(from: components)! } /** @@ -526,15 +526,15 @@ public extension NSDate { - Returns A new date object. */ - func dateAtStartOfWeek() -> NSDate + func dateAtStartOfWeek() -> Date { - let flags :NSCalendarUnit = [NSCalendarUnit.Year, NSCalendarUnit.Month, NSCalendarUnit.WeekOfYear, NSCalendarUnit.Weekday] - let components = NSCalendar.currentCalendar().components(flags, fromDate: self) - components.weekday = NSCalendar.currentCalendar().firstWeekday + let flags: Set = [Calendar.Component.year, Calendar.Component.month, Calendar.Component.weekOfYear, Calendar.Component.weekday] + var components = Calendar.current.dateComponents(flags, from: self) + components.weekday = Calendar.current.firstWeekday components.hour = 0 components.minute = 0 components.second = 0 - return NSCalendar.currentCalendar().dateFromComponents(components)! + return Calendar.current.date(from: components)! } /** @@ -542,15 +542,15 @@ public extension NSDate { - Returns A new date object. */ - func dateAtEndOfWeek() -> NSDate + func dateAtEndOfWeek() -> Date { - let flags :NSCalendarUnit = [NSCalendarUnit.Year, NSCalendarUnit.Month, NSCalendarUnit.WeekOfYear, NSCalendarUnit.Weekday] - let components = NSCalendar.currentCalendar().components(flags, fromDate: self) - components.weekday = NSCalendar.currentCalendar().firstWeekday + 6 + let flags: Set = [Calendar.Component.year, Calendar.Component.month, Calendar.Component.weekOfYear, Calendar.Component.weekday] + var components = Calendar.current.dateComponents(flags, from: self) + components.weekday = Calendar.current.firstWeekday + 6 components.hour = 0 components.minute = 0 components.second = 0 - return NSCalendar.currentCalendar().dateFromComponents(components)! + return Calendar.current.date(from: components)! } /** @@ -558,13 +558,13 @@ public extension NSDate { - Returns A new date object. */ - func dateAtTheStartOfMonth() -> NSDate + func dateAtTheStartOfMonth() -> Date { //Create the date components - let components = self.components() + var components = self.components() components.day = 1 //Builds the first day of the month - let firstDayOfMonthDate :NSDate = NSCalendar.currentCalendar().dateFromComponents(components)! + let firstDayOfMonthDate :Date = Calendar.current.date(from: components)! return firstDayOfMonthDate @@ -575,16 +575,16 @@ public extension NSDate { - Returns A new date object. */ - func dateAtTheEndOfMonth() -> NSDate { + func dateAtTheEndOfMonth() -> Date { //Create the date components - let components = self.components() + var components = self.components() //Set the last day of this month - components.month += 1 + components.month = (components.month ?? 0) + 1 components.day = 0 //Builds the first day of the month - let lastDayOfMonth :NSDate = NSCalendar.currentCalendar().dateFromComponents(components)! + let lastDayOfMonth :Date = Calendar.current.date(from: components)! return lastDayOfMonth @@ -595,9 +595,9 @@ public extension NSDate { - Returns A new date object. */ - class func tomorrow() -> NSDate + static func tomorrow() -> Date { - return NSDate().dateByAddingDays(1).dateAtStartOfDay() + return Date().dateByAddingDays(1).dateAtStartOfDay() } /** @@ -605,9 +605,9 @@ public extension NSDate { - Returns A new date object. */ - class func yesterday() -> NSDate + static func yesterday() -> Date { - return NSDate().dateBySubtractingDays(1).dateAtStartOfDay() + return Date().dateBySubtractingDays(1).dateAtStartOfDay() } /** @@ -615,12 +615,12 @@ public extension NSDate { :returns: NSDate */ - func setTimeOfDate(hour hour: Int, minute: Int, second: Int) -> NSDate { - let components = self.components() + func setTimeOfDate(_ hour: Int, minute: Int, second: Int) -> Date { + var components = self.components() components.hour = hour components.minute = minute components.second = second - return NSCalendar.currentCalendar().dateFromComponents(components)! + return Calendar.current.date(from: components)! } @@ -632,9 +632,9 @@ public extension NSDate { - Parameter date: the date to compare. - Returns The number of seconds */ - func secondsAfterDate(date: NSDate) -> Int + func secondsAfterDate(_ date: Date) -> Int { - return Int(self.timeIntervalSinceDate(date)) + return Int(self.timeIntervalSince(date)) } /** @@ -643,9 +643,9 @@ public extension NSDate { - Parameter date: The date to compare. - Returns The number of seconds */ - func secondsBeforeDate(date: NSDate) -> Int + func secondsBeforeDate(_ date: Date) -> Int { - return Int(date.timeIntervalSinceDate(self)) + return Int(date.timeIntervalSince(self)) } /** @@ -654,10 +654,10 @@ public extension NSDate { - Parameter date: the date to compare. - Returns The number of minutes */ - func minutesAfterDate(date: NSDate) -> Int + func minutesAfterDate(_ date: Date) -> Int { - let interval = self.timeIntervalSinceDate(date) - return Int(interval / NSDate.minuteInSeconds()) + let interval = self.timeIntervalSince(date) + return Int(interval / Date.minuteInSeconds()) } /** @@ -666,10 +666,10 @@ public extension NSDate { - Parameter date: The date to compare. - Returns The number of minutes */ - func minutesBeforeDate(date: NSDate) -> Int + func minutesBeforeDate(_ date: Date) -> Int { - let interval = date.timeIntervalSinceDate(self) - return Int(interval / NSDate.minuteInSeconds()) + let interval = date.timeIntervalSince(self) + return Int(interval / Date.minuteInSeconds()) } /** @@ -678,10 +678,10 @@ public extension NSDate { - Parameter date: The date to compare. - Returns The number of hours */ - func hoursAfterDate(date: NSDate) -> Int + func hoursAfterDate(_ date: Date) -> Int { - let interval = self.timeIntervalSinceDate(date) - return Int(interval / NSDate.hourInSeconds()) + let interval = self.timeIntervalSince(date) + return Int(interval / Date.hourInSeconds()) } /** @@ -690,10 +690,10 @@ public extension NSDate { - Parameter date: The date to compare. - Returns The number of hours */ - func hoursBeforeDate(date: NSDate) -> Int + func hoursBeforeDate(_ date: Date) -> Int { - let interval = date.timeIntervalSinceDate(self) - return Int(interval / NSDate.hourInSeconds()) + let interval = date.timeIntervalSince(self) + return Int(interval / Date.hourInSeconds()) } /** @@ -702,10 +702,10 @@ public extension NSDate { - Parameter date: The date to compare. - Returns The number of days */ - func daysAfterDate(date: NSDate) -> Int + func daysAfterDate(_ date: Date) -> Int { - let interval = self.timeIntervalSinceDate(date) - return Int(interval / NSDate.dayInSeconds()) + let interval = self.timeIntervalSince(date) + return Int(interval / Date.dayInSeconds()) } /** @@ -714,10 +714,10 @@ public extension NSDate { - Parameter date: The date to compare. - Returns The number of days */ - func daysBeforeDate(date: NSDate) -> Int + func daysBeforeDate(_ date: Date) -> Int { - let interval = date.timeIntervalSinceDate(self) - return Int(interval / NSDate.dayInSeconds()) + let interval = date.timeIntervalSince(self) + return Int(interval / Date.dayInSeconds()) } @@ -727,72 +727,75 @@ public extension NSDate { Returns the nearest hour. */ func nearestHour () -> Int { - let halfHour = NSDate.minuteInSeconds() * 30 + let halfHour = Date.minuteInSeconds() * 30 var interval = self.timeIntervalSinceReferenceDate if self.seconds() < 30 { interval -= halfHour } else { interval += halfHour } - let date = NSDate(timeIntervalSinceReferenceDate: interval) + let date = Date(timeIntervalSinceReferenceDate: interval) return date.hour() } /** Returns the year component. */ - func year () -> Int { return self.components().year } + func year () -> Int { return self.components().year! } /** Returns the month component. */ - func month () -> Int { return self.components().month } + func month () -> Int { return self.components().month! } /** Returns the week of year component. */ - func week () -> Int { return self.components().weekOfYear } + func week () -> Int { return self.components().weekOfYear! } /** Returns the day component. */ - func day () -> Int { return self.components().day } + func day () -> Int { return self.components().day! } /** Returns the hour component. */ - func hour () -> Int { return self.components().hour } + func hour () -> Int { return self.components().hour! } /** Returns the minute component. */ - func minute () -> Int { return self.components().minute } + func minute () -> Int { return self.components().minute! } /** Returns the seconds component. */ - func seconds () -> Int { return self.components().second } + func seconds () -> Int { return self.components().second! } /** Returns the weekday component. */ - func weekday () -> Int { return self.components().weekday } + func weekday () -> Int { return self.components().weekday! } /** Returns the nth days component. e.g. 2nd Tuesday of the month is 2. */ - func nthWeekday () -> Int { return self.components().weekdayOrdinal } + func nthWeekday () -> Int { return self.components().weekdayOrdinal! } /** Returns the days of the month. */ - func monthDays () -> Int { return NSCalendar.currentCalendar().rangeOfUnit(NSCalendarUnit.Day, inUnit: NSCalendarUnit.Month, forDate: self).length } + func monthDays () -> Int { + let range = Calendar.current.range(of: Calendar.Component.day, in: Calendar.Component.month, for: self)! + return range.upperBound - range.lowerBound + } /** Returns the first day of the week. */ func firstDayOfWeek () -> Int { - let distanceToStartOfWeek = NSDate.dayInSeconds() * Double(self.components().weekday - 1) - let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate - distanceToStartOfWeek - return NSDate(timeIntervalSinceReferenceDate: interval).day() + let distanceToStartOfWeek = Date.dayInSeconds() * Double(self.components().weekday! - 1) + let interval: TimeInterval = self.timeIntervalSinceReferenceDate - distanceToStartOfWeek + return Date(timeIntervalSinceReferenceDate: interval).day() } /** Returns the last day of the week. */ func lastDayOfWeek () -> Int { - let distanceToStartOfWeek = NSDate.dayInSeconds() * Double(self.components().weekday - 1) - let distanceToEndOfWeek = NSDate.dayInSeconds() * Double(7) - let interval: NSTimeInterval = self.timeIntervalSinceReferenceDate - distanceToStartOfWeek + distanceToEndOfWeek - return NSDate(timeIntervalSinceReferenceDate: interval).day() + let distanceToStartOfWeek = Date.dayInSeconds() * Double(self.components().weekday! - 1) + let distanceToEndOfWeek = Date.dayInSeconds() * Double(7) + let interval: TimeInterval = self.timeIntervalSinceReferenceDate - distanceToStartOfWeek + distanceToEndOfWeek + return Date(timeIntervalSinceReferenceDate: interval).day() } /** Returns true if a weekday. @@ -804,8 +807,8 @@ public extension NSDate { Returns true if weekend. */ func isWeekend() -> Bool { - let range = NSCalendar.currentCalendar().maximumRangeOfUnit(NSCalendarUnit.Weekday) - return (self.weekday() == range.location || self.weekday() == range.length) + let range = Calendar.current.maximumRange(of: Calendar.Component.weekday)! + return (self.weekday() == range.lowerBound || self.weekday() == range.upperBound - range.lowerBound) } @@ -815,7 +818,7 @@ public extension NSDate { A string representation using short date and time style. */ func toString() -> String { - return self.toString(dateStyle: .ShortStyle, timeStyle: .ShortStyle, doesRelativeDateFormatting: false) + return self.toString(.short, timeStyle: .short, doesRelativeDateFormatting: false) } /** @@ -825,36 +828,36 @@ public extension NSDate { - Parameter timeZone: The time zone to interpret the date can be .Local, .UTC applies to Custom format only - Returns The date string representation */ - func toString(format format: DateFormat, timeZone: TimeZone = .Local) -> String + func toString(_ format: DateFormat, timeZone: TimeZone = .local) -> String { var dateFormat: String - let zone: NSTimeZone + let zone: Foundation.TimeZone switch format { - case .DotNet: - let offset = NSTimeZone.defaultTimeZone().secondsFromGMT / 3600 + case .dotNet: + let offset = Foundation.NSTimeZone.default.secondsFromGMT() / 3600 let nowMillis = 1000 * self.timeIntervalSince1970 return "/Date(\(nowMillis)\(offset))/" - case .ISO8601(let isoFormat): + case .iso8601(let isoFormat): dateFormat = (isoFormat != nil) ? isoFormat!.rawValue : ISO8601Format.DateTimeMilliSec.rawValue - zone = NSTimeZone.localTimeZone() - case .RSS: + zone = NSTimeZone.local + case .rss: dateFormat = RSSFormat - zone = NSTimeZone.localTimeZone() - case .AltRSS: + zone = NSTimeZone.local + case .altRSS: dateFormat = AltRSSFormat - zone = NSTimeZone.localTimeZone() - case .Custom(let string): + zone = NSTimeZone.local + case .custom(let string): switch timeZone { - case .Local: - zone = NSTimeZone.localTimeZone() - case .UTC: - zone = NSTimeZone(forSecondsFromGMT: 0) + case .local: + zone = NSTimeZone.local + case .utc: + zone = Foundation.TimeZone(secondsFromGMT: 0)! } dateFormat = string } - let formatter = NSDate.formatter(format: dateFormat, timeZone: zone) - return formatter.stringFromDate(self) + let formatter = Date.formatter(dateFormat, timeZone: zone) + return formatter.string(from: self) } /** @@ -867,10 +870,10 @@ public extension NSDate { - Parameter locale: The locale to use. - Returns A string representation of the date. */ - func toString(dateStyle dateStyle: NSDateFormatterStyle, timeStyle: NSDateFormatterStyle, doesRelativeDateFormatting: Bool = false, timeZone: NSTimeZone = NSTimeZone.localTimeZone(), locale: NSLocale = NSLocale.currentLocale()) -> String + func toString(_ dateStyle: DateFormatter.Style, timeStyle: DateFormatter.Style, doesRelativeDateFormatting: Bool = false, timeZone: Foundation.TimeZone = Foundation.NSTimeZone.local, locale: Locale = Locale.current) -> String { - let formatter = NSDate.formatter(dateStyle: dateStyle, timeStyle: timeStyle, doesRelativeDateFormatting: doesRelativeDateFormatting, timeZone: timeZone, locale: locale) - return formatter.stringFromDate(self) + let formatter = Date.formatter(dateStyle, timeStyle: timeStyle, doesRelativeDateFormatting: doesRelativeDateFormatting, timeZone: timeZone, locale: locale) + return formatter.string(from: self) } /** @@ -879,7 +882,7 @@ public extension NSDate { func relativeTimeToString() -> String { let time = self.timeIntervalSince1970 - let now = NSDate().timeIntervalSince1970 + let now = Date().timeIntervalSince1970 let timeIsInPast = now - time > 0 @@ -888,7 +891,7 @@ public extension NSDate { let hours = round(minutes/60) let days = round(hours/24) - func describe(time: String) -> String { + func describe(_ time: String) -> String { if timeIsInPast { return "\(time) ago" } else { return "in \(time)" } } @@ -934,7 +937,7 @@ public extension NSDate { A string representation of the weekday. */ func weekdayToString() -> String { - let formatter = NSDate.formatter() + let formatter = Date.formatter() return formatter.weekdaySymbols[self.weekday()-1] as String } @@ -942,7 +945,7 @@ public extension NSDate { A short string representation of the weekday. */ func shortWeekdayToString() -> String { - let formatter = NSDate.formatter() + let formatter = Date.formatter() return formatter.shortWeekdaySymbols[self.weekday()-1] as String } @@ -952,7 +955,7 @@ public extension NSDate { - Returns String */ func veryShortWeekdayToString() -> String { - let formatter = NSDate.formatter() + let formatter = Date.formatter() return formatter.veryShortWeekdaySymbols[self.weekday()-1] as String } @@ -962,7 +965,7 @@ public extension NSDate { - Returns String */ func monthToString() -> String { - let formatter = NSDate.formatter() + let formatter = Date.formatter() return formatter.monthSymbols[self.month()-1] as String } @@ -972,7 +975,7 @@ public extension NSDate { - Returns String */ func shortMonthToString() -> String { - let formatter = NSDate.formatter() + let formatter = Date.formatter() return formatter.shortMonthSymbols[self.month()-1] as String } @@ -982,7 +985,7 @@ public extension NSDate { - Returns String */ func veryShortMonthToString() -> String { - let formatter = NSDate.formatter() + let formatter = Date.formatter() return formatter.veryShortMonthSymbols[self.month()-1] as String } @@ -992,13 +995,9 @@ public extension NSDate { /** Returns a cached static array of NSDateFormatters so that thy are only created once. */ - private class func sharedDateFormatters() -> [String: NSDateFormatter] { + private static func sharedDateFormatters() -> [String: DateFormatter] { struct Static { - static var formatters: [String: NSDateFormatter]? = nil - static var once: dispatch_once_t = 0 - } - dispatch_once(&Static.once) { - Static.formatters = [String: NSDateFormatter]() + static var formatters: [String: DateFormatter]? = [String: DateFormatter]() } return Static.formatters! } @@ -1011,13 +1010,13 @@ public extension NSDate { - Parameter locale: The locale to use, defaults to the current locale - Returns The date formatter. */ - private class func formatter(format format:String = DefaultFormat, timeZone: NSTimeZone = NSTimeZone.localTimeZone(), locale: NSLocale = NSLocale.currentLocale()) -> NSDateFormatter { + private static func formatter(_ format:String = DefaultFormat, timeZone: Foundation.TimeZone = Foundation.TimeZone.current, locale: Locale = Locale.current) -> DateFormatter { let hashKey = "\(format.hashValue)\(timeZone.hashValue)\(locale.hashValue)" - var formatters = NSDate.sharedDateFormatters() + var formatters = Date.sharedDateFormatters() if let cachedDateFormatter = formatters[hashKey] { return cachedDateFormatter } else { - let formatter = NSDateFormatter() + let formatter = DateFormatter() formatter.dateFormat = format formatter.timeZone = timeZone formatter.locale = locale @@ -1036,13 +1035,13 @@ public extension NSDate { - Parameter locale: The locale to use. - Returns The date formatter. */ - private class func formatter(dateStyle dateStyle: NSDateFormatterStyle, timeStyle: NSDateFormatterStyle, doesRelativeDateFormatting: Bool, timeZone: NSTimeZone = NSTimeZone.localTimeZone(), locale: NSLocale = NSLocale.currentLocale()) -> NSDateFormatter { - var formatters = NSDate.sharedDateFormatters() + private static func formatter(_ dateStyle: DateFormatter.Style, timeStyle: DateFormatter.Style, doesRelativeDateFormatting: Bool, timeZone: Foundation.TimeZone = Foundation.NSTimeZone.local, locale: Locale = Locale.current) -> DateFormatter { + var formatters = Date.sharedDateFormatters() let hashKey = "\(dateStyle.hashValue)\(timeStyle.hashValue)\(doesRelativeDateFormatting.hashValue)\(timeZone.hashValue)\(locale.hashValue)" if let cachedDateFormatter = formatters[hashKey] { return cachedDateFormatter } else { - let formatter = NSDateFormatter() + let formatter = DateFormatter() formatter.dateStyle = dateStyle formatter.timeStyle = timeStyle formatter.doesRelativeDateFormatting = doesRelativeDateFormatting @@ -1055,4 +1054,4 @@ public extension NSDate { -} \ No newline at end of file +} diff --git a/AppDemo/AppDelegate.swift b/AppDemo/AppDelegate.swift index d93cdff..0b43eb0 100644 --- a/AppDemo/AppDelegate.swift +++ b/AppDemo/AppDelegate.swift @@ -11,7 +11,7 @@ import UIKit class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { return true } } diff --git a/AppDemo/ViewController.swift b/AppDemo/ViewController.swift index 3146467..6f0e16f 100644 --- a/AppDemo/ViewController.swift +++ b/AppDemo/ViewController.swift @@ -15,8 +15,8 @@ struct TableItem { class ViewController: UITableViewController { - let now = NSDate() - var date = NSDate() + let now = Date() + var date = Date() var sections:[String] = [] var items:[[TableItem]] = [] @@ -30,43 +30,43 @@ class ViewController: UITableViewController { var sectionItems = [TableItem]() // MARK: Date from string with custom format - date = NSDate(fromString: "16 July 1972 6:12:00", format: .Custom("dd MMM yyyy HH:mm:ss")) + date = Date(fromString: "16 July 1972 6:12:00", format: .custom("dd MMM yyyy HH:mm:ss")) sectionItems.append(TableItem(title: "Custom Format", description: "dd MMM yyyy HH:mm:ss = \(date.toString())")) // MARK: Date from ISO8601(Year) String - date = NSDate(fromString: "2009", format: .ISO8601(nil)) + date = Date(fromString: "2009", format: .iso8601(nil)) sectionItems.append(TableItem(title: "ISO8601(Year)", description: "2009 = \(date.toString())")) // MARK: Date from ISO8601(Year & Month) String - date = NSDate(fromString: "2009-08", format: .ISO8601(nil)) + date = Date(fromString: "2009-08", format: .iso8601(nil)) sectionItems.append(TableItem(title: "ISO8601(Year & Month)", description: "2009-08 = \(date.toString())")) // MARK: Date from ISO8601(Date) String - date = NSDate(fromString: "2009-08-11", format: .ISO8601(nil)) + date = Date(fromString: "2009-08-11", format: .iso8601(nil)) sectionItems.append(TableItem(title: "ISO8601(Date)", description: "2009-08-11 = \(date.toString())")) // MARK: Date from ISO8601(Date & Time) String - date = NSDate(fromString: "2009-08-11T06:00-07:00", format: .ISO8601(nil)) + date = Date(fromString: "2009-08-11T06:00-07:00", format: .iso8601(nil)) sectionItems.append(TableItem(title: "ISO8601(Date & Time)", description: "2009-08-11T06:00-07:00 = \(date.toString())")) // MARK: Date from ISO8601(Date & Time & Sec) String - date = NSDate(fromString: "2009-08-11T06:00:00-07:00", format: .ISO8601(nil)) + date = Date(fromString: "2009-08-11T06:00:00-07:00", format: .iso8601(nil)) sectionItems.append(TableItem(title: "ISO8601(Date & Time & Sec)", description: "2009-08-11T06:00:00-07:00 = \(date.toString())")) // MARK: Date from ISO8601(Date & Time & MilliSec) String - date = NSDate(fromString: "2009-08-11T06:00:00.000-07:00", format: .ISO8601(nil)) + date = Date(fromString: "2009-08-11T06:00:00.000-07:00", format: .iso8601(nil)) sectionItems.append(TableItem(title: "ISO8601(Date & Time & MilliSec)", description: "2009-08-11T06:00:00.000-07:00 = \(date.toString())")) // MARK: Date from DotNetJSON String - date = NSDate(fromString: "/Date(1260123281843)/", format: .DotNet) + date = Date(fromString: "/Date(1260123281843)/", format: .dotNet) sectionItems.append(TableItem(title: "DotNetJSON", description: "Date(1260123281843) = \(date.toString())")) // MARK: Date from RSS String - date = NSDate(fromString: "Fri, 09 Sep 2011 15:26:08 +0200", format: .RSS) + date = Date(fromString: "Fri, 09 Sep 2011 15:26:08 +0200", format: .rss) sectionItems.append(TableItem(title: "RSS", description:"Fri, 09 Sep 2011 15:26:08 +0200 = \(date.toString())")) // MARK: Date from AltRSS String - date = NSDate(fromString: "09 Sep 2011 15:26:08 +0200", format: .AltRSS) + date = Date(fromString: "09 Sep 2011 15:26:08 +0200", format: .altRSS) sectionItems.append(TableItem(title: "Alt RSS", description: "09 Sep 2011 15:26:08 +0200 = \(date.toString())")) items.append(sectionItems) @@ -74,8 +74,8 @@ class ViewController: UITableViewController { // MARK: **** CREATING DATES **** sectionItems = [TableItem]() sections.append("Creating Dates") - sectionItems.append(TableItem(title: "Tomorrow", description: "\(NSDate.tomorrow())")) - sectionItems.append(TableItem(title: "Yesterday", description: "\(NSDate.yesterday())")) + sectionItems.append(TableItem(title: "Tomorrow", description: "\(Date.tomorrow())")) + sectionItems.append(TableItem(title: "Yesterday", description: "\(Date.yesterday())")) items.append(sectionItems) // MARK: **** COMPARING DATES **** @@ -239,7 +239,7 @@ class ViewController: UITableViewController { sectionItems.append(TableItem(title: "End of Month", description: "\(date.toString())")) // MARK: setTimeOfDate - date = now.setTimeOfDate(hour: 6, minute: 30, second: 15) + date = now.setTimeOfDate(6, minute: 30, second: 15) sectionItems.append(TableItem(title: "Set Time of Date", description: "\(date.toString())")) items.append(sectionItems) @@ -328,49 +328,49 @@ class ViewController: UITableViewController { sectionItems.append(TableItem(title: "toString()", description: now.toString())) // MARK: toString Cutom Format - sectionItems.append(TableItem(title: "Custom: dd MMM yyyy HH:mm:ss", description: now.toString(format: .Custom("dd MMM yyyy HH:mm:ss")))) + sectionItems.append(TableItem(title: "Custom: dd MMM yyyy HH:mm:ss", description: now.toString(.custom("dd MMM yyyy HH:mm:ss")))) // MARK: toString ISO8601(Year) - sectionItems.append(TableItem(title: "ISO8601(Year)", description: now.toString(format: .ISO8601(ISO8601Format.Year)))) + sectionItems.append(TableItem(title: "ISO8601(Year)", description: now.toString(.iso8601(ISO8601Format.Year)))) // MARK: toString ISO8601(Year & Month) - sectionItems.append(TableItem(title: "ISO8601(Year & Month)", description: now.toString(format: .ISO8601(ISO8601Format.YearMonth)))) + sectionItems.append(TableItem(title: "ISO8601(Year & Month)", description: now.toString(.iso8601(ISO8601Format.YearMonth)))) // MARK: toString ISO8601(Date) - sectionItems.append(TableItem(title: "ISO8601(Date)", description: now.toString(format: .ISO8601(ISO8601Format.Date)))) + sectionItems.append(TableItem(title: "ISO8601(Date)", description: now.toString(.iso8601(ISO8601Format.Date)))) // MARK: toString ISO8601(Date & Time) - sectionItems.append(TableItem(title: "ISO8601(Date & Time)", description: now.toString(format: .ISO8601(ISO8601Format.DateTime)))) + sectionItems.append(TableItem(title: "ISO8601(Date & Time)", description: now.toString(.iso8601(ISO8601Format.DateTime)))) // MARK: toString ISO8601(Date & Time & Sec) - sectionItems.append(TableItem(title: "ISO8601(Date & Time & Sec)", description: now.toString(format: .ISO8601(ISO8601Format.DateTimeSec)))) + sectionItems.append(TableItem(title: "ISO8601(Date & Time & Sec)", description: now.toString(.iso8601(ISO8601Format.DateTimeSec)))) // MARK: toString ISO8601(Date & Time & MilliSec) - sectionItems.append(TableItem(title: "ISO8601(Date & Time & MilliSec)", description: now.toString(format: .ISO8601(ISO8601Format.DateTimeMilliSec)))) + sectionItems.append(TableItem(title: "ISO8601(Date & Time & MilliSec)", description: now.toString(.iso8601(ISO8601Format.DateTimeMilliSec)))) // MARK: toString DotNet JSON - sectionItems.append(TableItem(title: "DotNet JSON", description: now.toString(format: .DotNet))) + sectionItems.append(TableItem(title: "DotNet JSON", description: now.toString(.dotNet))) // MARK: toString RSS - sectionItems.append(TableItem(title: "RSS", description: now.toString(format: .RSS))) + sectionItems.append(TableItem(title: "RSS", description: now.toString(.rss))) // MARK: toString AltRSS - sectionItems.append(TableItem(title: "AltRSS", description: now.toString(format: .AltRSS))) + sectionItems.append(TableItem(title: "AltRSS", description: now.toString(.altRSS))) // MARK: toString Short Date, No Time, Relative - sectionItems.append(TableItem(title: "Short Date, No Time, Relative", description: now.toString(dateStyle: .ShortStyle, timeStyle: .NoStyle, doesRelativeDateFormatting: true))) + sectionItems.append(TableItem(title: "Short Date, No Time, Relative", description: now.toString(.short, timeStyle: .none, doesRelativeDateFormatting: true))) // MARK: toString Short Date, Short Time, Not Relative - sectionItems.append(TableItem(title: "Short Date, Short Time, Not Relative", description: now.toString(dateStyle: .ShortStyle, timeStyle: .ShortStyle, doesRelativeDateFormatting: false))) + sectionItems.append(TableItem(title: "Short Date, Short Time, Not Relative", description: now.toString(.short, timeStyle: .short, doesRelativeDateFormatting: false))) // MARK: toString Medium Date, Medium Time, Not Relative - sectionItems.append(TableItem(title: "Medium Date, Medium Time, Not Relative", description: now.toString(dateStyle: .MediumStyle, timeStyle: .MediumStyle, doesRelativeDateFormatting: false))) + sectionItems.append(TableItem(title: "Medium Date, Medium Time, Not Relative", description: now.toString(.medium, timeStyle: .medium, doesRelativeDateFormatting: false))) // MARK: toString Long Date, Long Time, Not Relative - sectionItems.append(TableItem(title: "Long Date, Long Time, Not Relative", description: now.toString(dateStyle: .LongStyle, timeStyle: .LongStyle, doesRelativeDateFormatting: false))) + sectionItems.append(TableItem(title: "Long Date, Long Time, Not Relative", description: now.toString(.long, timeStyle: .long, doesRelativeDateFormatting: false))) // MARK: toString Full Date, Full Time, Not Relative - sectionItems.append(TableItem(title: "Full Date, Full Time, Not Relative", description: now.toString(dateStyle: .FullStyle, timeStyle: .FullStyle, doesRelativeDateFormatting: false))) + sectionItems.append(TableItem(title: "Full Date, Full Time, Not Relative", description: now.toString(.full, timeStyle: .full, doesRelativeDateFormatting: false))) // MARK: Relative Time sectionItems.append(TableItem(title: "Relative Time", description: now.relativeTimeToString())) @@ -405,25 +405,25 @@ class ViewController: UITableViewController { } - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + override func numberOfSections(in tableView: UITableView) -> Int { return items.count } - override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sections[section] } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items[section].count } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell - let item = items[indexPath.section][indexPath.row] + let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell + let item = items[(indexPath as NSIndexPath).section][(indexPath as NSIndexPath).row] cell.textLabel?.text = item.title cell.detailTextLabel?.text = item.description