diff --git a/.swift-version b/.swift-version index 9f55b2cc..bf77d549 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +4.2 diff --git a/PasscodeLock.xcodeproj/project.pbxproj b/PasscodeLock.xcodeproj/project.pbxproj index 799f9144..cbbe2a09 100644 --- a/PasscodeLock.xcodeproj/project.pbxproj +++ b/PasscodeLock.xcodeproj/project.pbxproj @@ -710,6 +710,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -762,6 +763,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -786,7 +788,6 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -806,7 +807,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.2; }; name = Release; }; @@ -821,7 +821,6 @@ SWIFT_OBJC_BRIDGING_HEADER = "PasscodeLockTests/PasscodeLockTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -835,7 +834,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PasscodeLockTests/PasscodeLockTests-Bridging-Header.h"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.2; }; name = Release; }; @@ -853,7 +851,6 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = "c4ef3957-2c3b-4abf-b8dd-d5d2c5712664"; PROVISIONING_PROFILE_SPECIFIER = "XC Ad Hoc: *"; - SWIFT_VERSION = 2.3; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -869,7 +866,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.yankodimitrov.PasscodeLockDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/PasscodeLock/PasscodeLockViewController.swift b/PasscodeLock/PasscodeLockViewController.swift index f05f7306..4befbb11 100644 --- a/PasscodeLock/PasscodeLockViewController.swift +++ b/PasscodeLock/PasscodeLockViewController.swift @@ -145,8 +145,8 @@ open class PasscodeLockViewController: UIViewController, PasscodeLockTypeDelegat fileprivate func setupEvents() { - notificationCenter?.addObserver(self, selector: #selector(self.appWillEnterForegroundHandler(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) - notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appDidEnterBackgroundHandler(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil) + notificationCenter?.addObserver(self, selector: #selector(self.appWillEnterForegroundHandler), name: UIApplication.willEnterForegroundNotification, object: nil) + notificationCenter?.addObserver(self, selector: #selector(self.appDidEnterBackgroundHandler), name: UIApplication.didEnterBackgroundNotification, object: nil) } fileprivate func clearEvents() { diff --git a/PasscodeLock/Views/PasscodeLockView.xib b/PasscodeLock/Views/PasscodeLockView.xib index 339d3782..76f8c2d3 100644 --- a/PasscodeLock/Views/PasscodeLockView.xib +++ b/PasscodeLock/Views/PasscodeLockView.xib @@ -1,12 +1,11 @@ - - + + - - + @@ -37,24 +36,24 @@ - + - + - + @@ -157,7 +156,7 @@ - + - + @@ -60,7 +64,7 @@ - + diff --git a/PasscodeLockDemo/PasscodeSettingsViewController.swift b/PasscodeLockDemo/PasscodeSettingsViewController.swift index 5bc806b1..a19f9a8c 100644 --- a/PasscodeLockDemo/PasscodeSettingsViewController.swift +++ b/PasscodeLockDemo/PasscodeSettingsViewController.swift @@ -35,7 +35,7 @@ class PasscodeSettingsViewController: UIViewController { // MARK: - View - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) updatePasscodeView() @@ -45,8 +45,8 @@ class PasscodeSettingsViewController: UIViewController { let hasPasscode = configuration.repository.hasPasscode - changePasscodeButton.hidden = !hasPasscode - passcodeSwitch.on = hasPasscode + changePasscodeButton.isHidden = !hasPasscode + passcodeSwitch.isOn = hasPasscode } // MARK: - Actions @@ -55,13 +55,13 @@ class PasscodeSettingsViewController: UIViewController { let passcodeVC: PasscodeLockViewController - if passcodeSwitch.on { + if passcodeSwitch.isOn { - passcodeVC = PasscodeLockViewController(state: .SetPasscode, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) + passcodeVC = PasscodeLockViewController(state: .setPasscode, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blue, font: UIFont.italicSystemFont(ofSize: 16)) } else { - passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) + passcodeVC = PasscodeLockViewController(state: .removePasscode, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blue, font: UIFont.italicSystemFont(ofSize: 16)) passcodeVC.successCallback = { lock in @@ -69,7 +69,7 @@ class PasscodeSettingsViewController: UIViewController { } } - presentViewController(passcodeVC, animated: true, completion: nil) + present(passcodeVC, animated: true, completion: nil) } @IBAction func changePasscodeButtonTap(sender: UIButton) { @@ -77,18 +77,18 @@ class PasscodeSettingsViewController: UIViewController { let repo = UserDefaultsPasscodeRepository() let config = PasscodeLockConfiguration(repository: repo) - let passcodeLock = PasscodeLockViewController(state: .ChangePasscode, configuration: config, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) + let passcodeLock = PasscodeLockViewController(state: .changePasscode, configuration: config, stringsToShow: nil, tintColor: UIColor.blue, font: UIFont.italicSystemFont(ofSize: 16)) - presentViewController(passcodeLock, animated: true, completion: nil) + present(passcodeLock, animated: true, completion: nil) } @IBAction func testAlertButtonTap(sender: UIButton) { - let alertVC = UIAlertController(title: "Test", message: "", preferredStyle: .Alert) + let alertVC = UIAlertController(title: "Test", message: "", preferredStyle: .alert) - alertVC.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil)) + alertVC.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil)) - presentViewController(alertVC, animated: true, completion: nil) + present(alertVC, animated: true, completion: nil) } @@ -97,9 +97,9 @@ class PasscodeSettingsViewController: UIViewController { let activityVC = UIActivityViewController(activityItems: ["Test"], applicationActivities: nil) activityVC.popoverPresentationController?.sourceView = testActivityButton - activityVC.popoverPresentationController?.sourceRect = CGRectMake(10, 20, 0, 0) + activityVC.popoverPresentationController?.sourceRect = CGRect(x: 10, y: 20, width: 0, height: 0) - presentViewController(activityVC, animated: true, completion: nil) + present(activityVC, animated: true, completion: nil) } @IBAction func dismissKeyboard() { diff --git a/PasscodeLockDemo/UserDefaultsPasscodeRepository.swift b/PasscodeLockDemo/UserDefaultsPasscodeRepository.swift index 696171a3..ca803e45 100644 --- a/PasscodeLockDemo/UserDefaultsPasscodeRepository.swift +++ b/PasscodeLockDemo/UserDefaultsPasscodeRepository.swift @@ -13,9 +13,9 @@ class UserDefaultsPasscodeRepository: PasscodeRepositoryType { private let passcodeKey = "passcode.lock.passcode" - private lazy var defaults: NSUserDefaults = { + private lazy var defaults: UserDefaults = { - return NSUserDefaults.standardUserDefaults() + return UserDefaults.standard }() var hasPasscode: Bool { @@ -29,18 +29,18 @@ class UserDefaultsPasscodeRepository: PasscodeRepositoryType { var passcode: [String]? { - return defaults.valueForKey(passcodeKey) as? [String] ?? nil + return defaults.value(forKey: passcodeKey) as? [String] ?? nil } - func savePasscode(passcode: [String]) { + func savePasscode(_ passcode: [String]) { - defaults.setObject(passcode, forKey: passcodeKey) + defaults.set(passcode, forKey: passcodeKey) defaults.synchronize() } func deletePasscode() { - defaults.removeObjectForKey(passcodeKey) + defaults.removeObject(forKey: passcodeKey) defaults.synchronize() } } diff --git a/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift b/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift index 986c59bf..e761c3f9 100644 --- a/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift +++ b/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift @@ -18,7 +18,7 @@ class NotificaionObserver: NSObject { let center = NotificationCenter.default - center.addObserver(self, selector: #selector(NotificaionObserver.handle(_:)), name: NSNotification.Name(rawValue: notification), object: nil) + center.addObserver(self, selector: #selector(NotificaionObserver.handle), name: NSNotification.Name(rawValue: notification), object: nil) } @objc func handle(_ notification: Notification) {