Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 3 and XCode 8 Support #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MTMigration.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pod::Spec.new do |s|
s.author = { "Parker Wightman" => "[email protected]" }
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
10 changes: 8 additions & 2 deletions Swift/MTMigration.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -151,9 +151,11 @@
TargetAttributes = {
DF3083CD1BD7DEC900E9361A = {
CreatedOnToolsVersion = 7.0.1;
LastSwiftMigration = 0820;
};
DF3083D71BD7DEC900E9361A = {
CreatedOnToolsVersion = 7.0.1;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -325,6 +327,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -343,6 +346,7 @@
PRODUCT_BUNDLE_IDENTIFIER = mystrou.MTMigration.MTMigration;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -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;
};
Expand All @@ -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;
};
Expand Down
66 changes: 33 additions & 33 deletions Swift/MTMigration/Migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ?? ""
}
}
36 changes: 18 additions & 18 deletions Swift/MTMigrationTests/MigrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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()
}
Expand All @@ -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)
}
Expand Down