diff --git a/MTMigration.podspec b/MTMigration.podspec index 483a3f2..45f47f3 100644 --- a/MTMigration.podspec +++ b/MTMigration.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.author = { "Parker Wightman" => "parkerwightman@gmail.com" } s.source = { :git => "https://github.com/mysterioustrousers/MTMigration.git", :tag => "#{s.version}" } s.source_files = 'MTMigration/MTMigration.{h,m}' - s.ios.deployment_target = '5.0' + s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.6' s.requires_arc = true end diff --git a/Swift/MTMigration.xcodeproj/project.pbxproj b/Swift/MTMigration.xcodeproj/project.pbxproj index 81936ae..2821bd8 100644 --- a/Swift/MTMigration.xcodeproj/project.pbxproj +++ b/Swift/MTMigration.xcodeproj/project.pbxproj @@ -8,9 +8,9 @@ /* Begin PBXBuildFile section */ DF3083D21BD7DEC900E9361A /* MTMigration.h in Headers */ = {isa = PBXBuildFile; fileRef = DF3083D11BD7DEC900E9361A /* MTMigration.h */; settings = {ATTRIBUTES = (Public, ); }; }; - DF3083D91BD7DEC900E9361A /* MTMigration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF3083CE1BD7DEC900E9361A /* MTMigration.framework */; settings = {ASSET_TAGS = (); }; }; + DF3083D91BD7DEC900E9361A /* MTMigration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF3083CE1BD7DEC900E9361A /* MTMigration.framework */; }; DF3083DE1BD7DEC900E9361A /* MigrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3083DD1BD7DEC900E9361A /* MigrationTests.swift */; }; - DF3083E91BD7DF0F00E9361A /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3083E81BD7DF0F00E9361A /* Migration.swift */; settings = {ASSET_TAGS = (); }; }; + DF3083E91BD7DF0F00E9361A /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3083E81BD7DF0F00E9361A /* Migration.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -151,9 +151,11 @@ TargetAttributes = { DF3083CD1BD7DEC900E9361A = { CreatedOnToolsVersion = 7.0.1; + LastSwiftMigration = 0820; }; DF3083D71BD7DEC900E9361A = { CreatedOnToolsVersion = 7.0.1; + LastSwiftMigration = 0820; }; }; }; @@ -325,6 +327,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -343,6 +346,7 @@ PRODUCT_BUNDLE_IDENTIFIER = mystrou.MTMigration.MTMigration; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -353,6 +357,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = mystrou.MTMigration.MTMigrationTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -363,6 +368,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = mystrou.MTMigration.MTMigrationTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Swift/MTMigration/Migration.swift b/Swift/MTMigration/Migration.swift index f843b8f..2d690e8 100644 --- a/Swift/MTMigration/Migration.swift +++ b/Swift/MTMigration/Migration.swift @@ -10,32 +10,32 @@ private let MigrationLastAppBuildKey = "Migration.lastAppBuild" public struct Migration { - static var AppBundle: NSBundle = NSBundle.mainBundle() + static var AppBundle: Bundle = Bundle.main - public static func migrateToVersion(version: String, closure: ExecutionClosure) { - if version.compare(self.lastMigrationVersion, options: [.NumericSearch]) == .OrderedDescending && - version.compare(self.appVersion, options: [.NumericSearch]) != .OrderedDescending { + public static func migrateToVersion(_ version: String, closure: ExecutionClosure) { + if version.compare(self.lastMigrationVersion, options: [.numeric]) == .orderedDescending && + version.compare(self.appVersion, options: [.numeric]) != .orderedDescending { closure() self.setLastMigrationVersion(version) } } - public static func migrateToBuild(build: String, closure: ExecutionClosure) { - if build.compare(self.lastMigrationBuild, options: [.NumericSearch]) == .OrderedDescending && - build.compare(self.appBuild, options: [.NumericSearch]) != .OrderedDescending { + public static func migrateToBuild(_ build: String, closure: ExecutionClosure) { + if build.compare(self.lastMigrationBuild, options: [.numeric]) == .orderedDescending && + build.compare(self.appBuild, options: [.numeric]) != .orderedDescending { closure() self.setLastMigrationBuild(build) } } - public static func applicationUpdate(closure: ExecutionClosure) { + public static func applicationUpdate(_ closure: ExecutionClosure) { if self.lastAppVersion != self.appVersion { closure() self.setLastAppVersion(self.appVersion) } } - public static func buildNumberUpdate(closure: ExecutionClosure) { + public static func buildNumberUpdate(_ closure: ExecutionClosure) { if self.lastAppBuild != self.appBuild { closure() self.setLastAppBuild(self.appBuild) @@ -51,47 +51,47 @@ public struct Migration { // MARK: - Private methods and properties - private static var appVersion: String { - return Migration.AppBundle.objectForInfoDictionaryKey("CFBundleShortVersionString") as? String ?? "" + fileprivate static var appVersion: String { + return Migration.AppBundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "" } - private static var appBuild: String { - return Migration.AppBundle.objectForInfoDictionaryKey("CFBundleVersion") as? String ?? "" + fileprivate static var appBuild: String { + return Migration.AppBundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "" } - private static func setLastMigrationVersion(version: String?) { - NSUserDefaults.standardUserDefaults().setValue(version, forKey: MigrationLastVersionKey) - NSUserDefaults.standardUserDefaults().synchronize() + fileprivate static func setLastMigrationVersion(_ version: String?) { + UserDefaults.standard.setValue(version, forKey: MigrationLastVersionKey) + UserDefaults.standard.synchronize() } - private static func setLastMigrationBuild(build: String?) { - NSUserDefaults.standardUserDefaults().setValue(build, forKey: MigrationLastBuildKey) - NSUserDefaults.standardUserDefaults().synchronize() + fileprivate static func setLastMigrationBuild(_ build: String?) { + UserDefaults.standard.setValue(build, forKey: MigrationLastBuildKey) + UserDefaults.standard.synchronize() } - private static var lastMigrationVersion: String { - return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastVersionKey) as? String ?? "" + fileprivate static var lastMigrationVersion: String { + return UserDefaults.standard.value(forKey: MigrationLastVersionKey) as? String ?? "" } - private static var lastMigrationBuild: String { - return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastBuildKey) as? String ?? "" + fileprivate static var lastMigrationBuild: String { + return UserDefaults.standard.value(forKey: MigrationLastBuildKey) as? String ?? "" } - private static func setLastAppVersion(version: String?) { - NSUserDefaults.standardUserDefaults().setValue(version, forKey: MigrationLastAppVersionKey) - NSUserDefaults.standardUserDefaults().synchronize() + fileprivate static func setLastAppVersion(_ version: String?) { + UserDefaults.standard.setValue(version, forKey: MigrationLastAppVersionKey) + UserDefaults.standard.synchronize() } - private static func setLastAppBuild(build: String?) { - NSUserDefaults.standardUserDefaults().setValue(build, forKey: MigrationLastAppBuildKey) - NSUserDefaults.standardUserDefaults().synchronize() + fileprivate static func setLastAppBuild(_ build: String?) { + UserDefaults.standard.setValue(build, forKey: MigrationLastAppBuildKey) + UserDefaults.standard.synchronize() } - private static var lastAppVersion: String { - return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastAppVersionKey) as? String ?? "" + fileprivate static var lastAppVersion: String { + return UserDefaults.standard.value(forKey: MigrationLastAppVersionKey) as? String ?? "" } - private static var lastAppBuild: String { - return NSUserDefaults.standardUserDefaults().valueForKey(MigrationLastAppBuildKey) as? String ?? "" + fileprivate static var lastAppBuild: String { + return UserDefaults.standard.value(forKey: MigrationLastAppBuildKey) as? String ?? "" } } diff --git a/Swift/MTMigrationTests/MigrationTests.swift b/Swift/MTMigrationTests/MigrationTests.swift index 8f3d03b..75c1e10 100644 --- a/Swift/MTMigrationTests/MigrationTests.swift +++ b/Swift/MTMigrationTests/MigrationTests.swift @@ -8,7 +8,7 @@ class MigrationTests: XCTestCase { Migration.reset() - let bundles: [NSBundle] = NSBundle.allBundles().filter { + let bundles: [Bundle] = Bundle.allBundles.filter { return ($0.bundleIdentifier != nil && $0.bundleIdentifier! == "mystrou.MTMigration.MTMigrationTests") } @@ -24,34 +24,34 @@ class MigrationTests: XCTestCase { } func testMigrationReset() { - let expectation1 = self.expectationWithDescription("Expecting block to be run for version 0.9") + let expectation1 = self.expectation(description: "Expecting block to be run for version 0.9") Migration.migrateToVersion("0.9") { () -> Void in expectation1.fulfill() } - let expectation2 = self.expectationWithDescription("Expecting block to be run for version 1.0") + let expectation2 = self.expectation(description: "Expecting block to be run for version 1.0") Migration.migrateToVersion("1.0") { () -> Void in expectation2.fulfill() } - let expectation3 = self.expectationWithDescription("Expecting block to be run for version 1.0") + let expectation3 = self.expectation(description: "Expecting block to be run for version 1.0") Migration.migrateToBuild("1") { () -> Void in expectation3.fulfill() } Migration.reset() - let expectation4 = self.expectationWithDescription("Expecting block to be run again for version 0.9") + let expectation4 = self.expectation(description: "Expecting block to be run again for version 0.9") Migration.migrateToVersion("0.9") { () -> Void in expectation4.fulfill() } - let expectation5 = self.expectationWithDescription("Expecting block to be run again for version 1.0") + let expectation5 = self.expectation(description: "Expecting block to be run again for version 1.0") Migration.migrateToVersion("1.0") { () -> Void in expectation5.fulfill() } - let expectation6 = self.expectationWithDescription("Expecting block to be run for version 1.0") + let expectation6 = self.expectation(description: "Expecting block to be run for version 1.0") Migration.migrateToBuild("1") { () -> Void in expectation6.fulfill() } @@ -60,7 +60,7 @@ class MigrationTests: XCTestCase { } func testMigratesOnFirstRun() { - let expectation = self.expectationWithDescription("Should execute migration after reset") + let expectation = self.expectation(description: "Should execute migration after reset") Migration.migrateToVersion("1.0") { () -> Void in expectation.fulfill() } @@ -69,7 +69,7 @@ class MigrationTests: XCTestCase { } func testMigratesOnce() { - let expectation = self.expectationWithDescription("Expecting block to be run") + let expectation = self.expectation(description: "Expecting block to be run") Migration.migrateToVersion("1.0") { () -> Void in expectation.fulfill() } @@ -82,12 +82,12 @@ class MigrationTests: XCTestCase { } func testMigratesPreviousBlocks() { - let expectation1 = self.expectationWithDescription("Expecting block to be run for version 0.9") + let expectation1 = self.expectation(description: "Expecting block to be run for version 0.9") Migration.migrateToVersion("0.9") { () -> Void in expectation1.fulfill() } - let expectation2 = self.expectationWithDescription("Expecting block to be run for version 1.0") + let expectation2 = self.expectation(description: "Expecting block to be run for version 1.0") Migration.migrateToVersion("1.0") { () -> Void in expectation2.fulfill() } @@ -96,7 +96,7 @@ class MigrationTests: XCTestCase { } func testMigratesInNaturalSortOrder() { - let expectation1 = self.expectationWithDescription("Expecting block to be run for version 0.9") + let expectation1 = self.expectation(description: "Expecting block to be run for version 0.9") Migration.migrateToVersion("0.9") { () -> Void in expectation1.fulfill() } @@ -105,7 +105,7 @@ class MigrationTests: XCTestCase { XCTFail("Should use natural sort order, e.g. treat 0.10 as a follower of 0.9") } - let expectation2 = self.expectationWithDescription("Expecting block to be run for version 0.10") + let expectation2 = self.expectation(description: "Expecting block to be run for version 0.10") Migration.migrateToVersion("0.10") { () -> Void in expectation2.fulfill() } @@ -114,7 +114,7 @@ class MigrationTests: XCTestCase { } func testRunsApplicationUpdateBlockOnce() { - let expectation = self.expectationWithDescription("Should only call block once") + let expectation = self.expectation(description: "Should only call block once") Migration.applicationUpdate { () -> Void in expectation.fulfill() } @@ -127,7 +127,7 @@ class MigrationTests: XCTestCase { } func testRunsBuildNumberUpdateBlockOnce() { - let expectation = self.expectationWithDescription("Should only call block once") + let expectation = self.expectation(description: "Should only call block once") Migration.buildNumberUpdate { () -> Void in expectation.fulfill() } @@ -152,7 +152,7 @@ class MigrationTests: XCTestCase { // Do something } - let expectation = self.expectationWithDescription("Should call the applicationUpdate only once no matter how many migrations have to be done") + let expectation = self.expectation(description: "Should call the applicationUpdate only once no matter how many migrations have to be done") Migration.applicationUpdate { () -> Void in expectation.fulfill() } @@ -173,7 +173,7 @@ class MigrationTests: XCTestCase { // Do something } - let expectation = self.expectationWithDescription("Should call the buildNumberUpdate only once no matter how many migrations have to be done") + let expectation = self.expectation(description: "Should call the buildNumberUpdate only once no matter how many migrations have to be done") Migration.buildNumberUpdate { () -> Void in expectation.fulfill() } @@ -182,7 +182,7 @@ class MigrationTests: XCTestCase { } func waitForAllExpectations() { - self.waitForExpectationsWithTimeout(2.0) { (error: NSError?) -> Void in + self.waitForExpectations(timeout: 2.0) { (error: NSError?) -> Void in if let error = error { print(error) }