From a431a7d2335cffadddb2279b602f961a3b0577b4 Mon Sep 17 00:00:00 2001 From: Giovanny Aranda Date: Tue, 23 Jul 2019 15:23:33 +0200 Subject: [PATCH 1/2] Swift 5 support --- PasscodeLock.xcodeproj/project.pbxproj | 94 ++++---- PasscodeLock/Functions.swift | 10 +- PasscodeLock/Info.plist | 0 PasscodeLock/PasscodeLock.h | 0 .../PasscodeLock/ChangePasscodeState.swift | 2 +- .../PasscodeLock/ConfirmPasscodeState.swift | 4 +- .../PasscodeLock/EnterPasscodeState.swift | 29 ++- PasscodeLock/PasscodeLock/PasscodeLock.swift | 47 ++-- .../PasscodeLock/SetPasscodeState.swift | 2 +- PasscodeLock/PasscodeLockPresenter.swift | 96 +++++---- PasscodeLock/PasscodeLockViewController.swift | 158 +++++++------- .../PasscodeLockConfigurationType.swift | 12 ++ .../Protocols/PasscodeLockStateType.swift | 2 +- PasscodeLock/Protocols/PasscodeLockType.swift | 16 +- .../Protocols/PasscodeRepositoryType.swift | 2 +- PasscodeLock/Views/PasscodeLockView.xib | 203 +++++++++--------- PasscodeLock/Views/PasscodeSignButton.swift | 38 ++-- .../Views/PasscodeSignPlaceholderView.swift | 38 ++-- PasscodeLockDemo/AppDelegate.swift | 21 +- .../AppIcon.appiconset/Contents.json | 30 +++ .../Assets.xcassets/Contents.json | 6 + PasscodeLockDemo/Base.lproj/Main.storyboard | 36 ++-- PasscodeLockDemo/Info.plist | 2 + .../PasscodeLockConfiguration.swift | 2 + .../PasscodeSettingsViewController.swift | 28 +-- .../UserDefaultsPasscodeRepository.swift | 12 +- PasscodeLockDemoTests/Info.plist | 0 PasscodeLockDemoUITests/Info.plist | 0 .../Fakes/FakePasscodeLock.swift | 4 +- .../Fakes/FakePasscodeLockConfiguration.swift | 2 +- .../Fakes/FakePasscodeLockDelegate.swift | 10 +- .../Fakes/FakePasscodeRepository.swift | 2 +- .../Fakes/FakePasscodeState.swift | 8 +- PasscodeLockTests/Info.plist | 2 + .../ChangePasscodeStateTests.swift | 4 +- .../ConfirmPasscodeStateTests.swift | 6 +- .../EnterPasscodeStateTests.swift | 14 +- .../PasscodeLock/PasscodeLockTests.swift | 6 +- .../PasscodeLock/SetPasscodeStateTests.swift | 2 +- .../PasscodeLockTests-Bridging-Header.h | 0 40 files changed, 528 insertions(+), 422 deletions(-) mode change 100644 => 100755 PasscodeLock/Functions.swift mode change 100644 => 100755 PasscodeLock/Info.plist mode change 100644 => 100755 PasscodeLock/PasscodeLock.h mode change 100644 => 100755 PasscodeLock/PasscodeLock/ChangePasscodeState.swift mode change 100644 => 100755 PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift mode change 100644 => 100755 PasscodeLock/PasscodeLock/EnterPasscodeState.swift mode change 100644 => 100755 PasscodeLock/PasscodeLock/PasscodeLock.swift mode change 100644 => 100755 PasscodeLock/PasscodeLock/SetPasscodeState.swift mode change 100644 => 100755 PasscodeLock/PasscodeLockPresenter.swift mode change 100644 => 100755 PasscodeLock/PasscodeLockViewController.swift mode change 100644 => 100755 PasscodeLock/Protocols/PasscodeLockConfigurationType.swift mode change 100644 => 100755 PasscodeLock/Protocols/PasscodeLockStateType.swift mode change 100644 => 100755 PasscodeLock/Protocols/PasscodeLockType.swift mode change 100644 => 100755 PasscodeLock/Protocols/PasscodeRepositoryType.swift mode change 100644 => 100755 PasscodeLock/Views/PasscodeLockView.xib mode change 100644 => 100755 PasscodeLock/Views/PasscodeSignButton.swift mode change 100644 => 100755 PasscodeLock/Views/PasscodeSignPlaceholderView.swift create mode 100644 PasscodeLockDemo/Assets.xcassets/Contents.json mode change 100644 => 100755 PasscodeLockDemoTests/Info.plist mode change 100644 => 100755 PasscodeLockDemoUITests/Info.plist mode change 100644 => 100755 PasscodeLockTests/Fakes/FakePasscodeLock.swift mode change 100644 => 100755 PasscodeLockTests/Fakes/FakePasscodeLockConfiguration.swift mode change 100644 => 100755 PasscodeLockTests/Fakes/FakePasscodeLockDelegate.swift mode change 100644 => 100755 PasscodeLockTests/Fakes/FakePasscodeRepository.swift mode change 100644 => 100755 PasscodeLockTests/Fakes/FakePasscodeState.swift mode change 100644 => 100755 PasscodeLockTests/Info.plist mode change 100644 => 100755 PasscodeLockTests/PasscodeLock/ChangePasscodeStateTests.swift mode change 100644 => 100755 PasscodeLockTests/PasscodeLock/ConfirmPasscodeStateTests.swift mode change 100644 => 100755 PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift mode change 100644 => 100755 PasscodeLockTests/PasscodeLock/PasscodeLockTests.swift mode change 100644 => 100755 PasscodeLockTests/PasscodeLock/SetPasscodeStateTests.swift mode change 100644 => 100755 PasscodeLockTests/PasscodeLockTests-Bridging-Header.h diff --git a/PasscodeLock.xcodeproj/project.pbxproj b/PasscodeLock.xcodeproj/project.pbxproj index 0849b504..d988a354 100644 --- a/PasscodeLock.xcodeproj/project.pbxproj +++ b/PasscodeLock.xcodeproj/project.pbxproj @@ -8,8 +8,8 @@ /* Begin PBXBuildFile section */ C99EAF431B90B05700D61E1B /* PasscodeLock.h in Headers */ = {isa = PBXBuildFile; fileRef = C99EAF421B90B05700D61E1B /* PasscodeLock.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C99EAF4A1B90B05800D61E1B /* PasscodeLock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C99EAF3F1B90B05700D61E1B /* PasscodeLock.framework */; settings = {ASSET_TAGS = (); }; }; - C9D3DF0B1B919CE4008561EB /* PasscodeLockView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9D3DF0A1B919CE4008561EB /* PasscodeLockView.xib */; settings = {ASSET_TAGS = (); }; }; + C99EAF4A1B90B05800D61E1B /* PasscodeLock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C99EAF3F1B90B05700D61E1B /* PasscodeLock.framework */; }; + C9D3DF0B1B919CE4008561EB /* PasscodeLockView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9D3DF0A1B919CE4008561EB /* PasscodeLockView.xib */; }; C9D3DF131B91AD11008561EB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF121B91AD11008561EB /* AppDelegate.swift */; }; C9D3DF151B91AD11008561EB /* PasscodeSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF141B91AD11008561EB /* PasscodeSettingsViewController.swift */; }; C9D3DF181B91AD11008561EB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9D3DF161B91AD11008561EB /* Main.storyboard */; }; @@ -17,45 +17,45 @@ C9D3DF1D1B91AD11008561EB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9D3DF1B1B91AD11008561EB /* LaunchScreen.storyboard */; }; C9D3DF3E1B91AD7A008561EB /* PasscodeLock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C99EAF3F1B90B05700D61E1B /* PasscodeLock.framework */; }; C9D3DF3F1B91AD7A008561EB /* PasscodeLock.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C99EAF3F1B90B05700D61E1B /* PasscodeLock.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - C9D3DF441B91B9CD008561EB /* UserDefaultsPasscodeRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF431B91B9CD008561EB /* UserDefaultsPasscodeRepository.swift */; settings = {ASSET_TAGS = (); }; }; - C9D3DF461B91BD0E008561EB /* PasscodeLockConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF451B91BD0E008561EB /* PasscodeLockConfiguration.swift */; settings = {ASSET_TAGS = (); }; }; - C9D3DF481B91F099008561EB /* PasscodeLockPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF471B91F099008561EB /* PasscodeLockPresenter.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07D51B90B1F6007A4DD0 /* PasscodeRepositoryType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D41B90B1F6007A4DD0 /* PasscodeRepositoryType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07D61B90B1F6007A4DD0 /* PasscodeRepositoryType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D41B90B1F6007A4DD0 /* PasscodeRepositoryType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07D81B90B261007A4DD0 /* PasscodeLockStateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D71B90B261007A4DD0 /* PasscodeLockStateType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07D91B90B261007A4DD0 /* PasscodeLockStateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D71B90B261007A4DD0 /* PasscodeLockStateType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07DB1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DA1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07DC1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DA1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07DE1B90BA06007A4DD0 /* PasscodeLockType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DD1B90BA06007A4DD0 /* PasscodeLockType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07DF1B90BA06007A4DD0 /* PasscodeLockType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DD1B90BA06007A4DD0 /* PasscodeLockType.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07E11B90BBFD007A4DD0 /* PasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E01B90BBFD007A4DD0 /* PasscodeLock.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07E21B90BBFD007A4DD0 /* PasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E01B90BBFD007A4DD0 /* PasscodeLock.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07E51B90BCF9007A4DD0 /* PasscodeLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E41B90BCF9007A4DD0 /* PasscodeLockTests.swift */; settings = {ASSET_TAGS = (); }; }; + C9D3DF441B91B9CD008561EB /* UserDefaultsPasscodeRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF431B91B9CD008561EB /* UserDefaultsPasscodeRepository.swift */; }; + C9D3DF461B91BD0E008561EB /* PasscodeLockConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF451B91BD0E008561EB /* PasscodeLockConfiguration.swift */; }; + C9D3DF481B91F099008561EB /* PasscodeLockPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D3DF471B91F099008561EB /* PasscodeLockPresenter.swift */; }; + C9DC07D51B90B1F6007A4DD0 /* PasscodeRepositoryType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D41B90B1F6007A4DD0 /* PasscodeRepositoryType.swift */; }; + C9DC07D61B90B1F6007A4DD0 /* PasscodeRepositoryType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D41B90B1F6007A4DD0 /* PasscodeRepositoryType.swift */; }; + C9DC07D81B90B261007A4DD0 /* PasscodeLockStateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D71B90B261007A4DD0 /* PasscodeLockStateType.swift */; }; + C9DC07D91B90B261007A4DD0 /* PasscodeLockStateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07D71B90B261007A4DD0 /* PasscodeLockStateType.swift */; }; + C9DC07DB1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DA1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift */; }; + C9DC07DC1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DA1B90B730007A4DD0 /* PasscodeLockConfigurationType.swift */; }; + C9DC07DE1B90BA06007A4DD0 /* PasscodeLockType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DD1B90BA06007A4DD0 /* PasscodeLockType.swift */; }; + C9DC07DF1B90BA06007A4DD0 /* PasscodeLockType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07DD1B90BA06007A4DD0 /* PasscodeLockType.swift */; }; + C9DC07E11B90BBFD007A4DD0 /* PasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E01B90BBFD007A4DD0 /* PasscodeLock.swift */; }; + C9DC07E21B90BBFD007A4DD0 /* PasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E01B90BBFD007A4DD0 /* PasscodeLock.swift */; }; + C9DC07E51B90BCF9007A4DD0 /* PasscodeLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E41B90BCF9007A4DD0 /* PasscodeLockTests.swift */; }; C9DC07E71B90C382007A4DD0 /* LocalAuthentication.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9DC07E61B90C382007A4DD0 /* LocalAuthentication.framework */; }; - C9DC07EA1B90C690007A4DD0 /* FakePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E91B90C690007A4DD0 /* FakePasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07EC1B90C72A007A4DD0 /* FakePasscodeRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07EB1B90C72A007A4DD0 /* FakePasscodeRepository.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07EE1B90C7CD007A4DD0 /* FakePasscodeLockConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07ED1B90C7CD007A4DD0 /* FakePasscodeLockConfiguration.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07F01B90C8E1007A4DD0 /* FakePasscodeLockDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07EF1B90C8E1007A4DD0 /* FakePasscodeLockDelegate.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07F21B90C9DE007A4DD0 /* EnterPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F11B90C9DE007A4DD0 /* EnterPasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07F31B90C9DE007A4DD0 /* EnterPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F11B90C9DE007A4DD0 /* EnterPasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07F81B90CF29007A4DD0 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F71B90CF29007A4DD0 /* Functions.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07F91B90CF29007A4DD0 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F71B90CF29007A4DD0 /* Functions.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC07FC1B90D0A3007A4DD0 /* PasscodeLock.strings in Resources */ = {isa = PBXBuildFile; fileRef = C9DC07FA1B90D0A3007A4DD0 /* PasscodeLock.strings */; settings = {ASSET_TAGS = (); }; }; - C9DC07FD1B90D0A3007A4DD0 /* PasscodeLock.strings in Resources */ = {isa = PBXBuildFile; fileRef = C9DC07FA1B90D0A3007A4DD0 /* PasscodeLock.strings */; settings = {ASSET_TAGS = (); }; }; - C9DC07FF1B90D24A007A4DD0 /* SetPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07FE1B90D24A007A4DD0 /* SetPasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08001B90D24A007A4DD0 /* SetPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07FE1B90D24A007A4DD0 /* SetPasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08021B90D2BA007A4DD0 /* ConfirmPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08011B90D2BA007A4DD0 /* ConfirmPasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08031B90D2BA007A4DD0 /* ConfirmPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08011B90D2BA007A4DD0 /* ConfirmPasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08051B90D394007A4DD0 /* ChangePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08041B90D394007A4DD0 /* ChangePasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08061B90D394007A4DD0 /* ChangePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08041B90D394007A4DD0 /* ChangePasscodeState.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08081B90DAE6007A4DD0 /* EnterPasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08071B90DAE6007A4DD0 /* EnterPasscodeStateTests.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC080A1B90DB09007A4DD0 /* FakePasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08091B90DB09007A4DD0 /* FakePasscodeLock.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC080C1B90DC38007A4DD0 /* SetPasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC080B1B90DC38007A4DD0 /* SetPasscodeStateTests.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC080E1B90DC8F007A4DD0 /* ConfirmPasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC080D1B90DC8F007A4DD0 /* ConfirmPasscodeStateTests.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08101B90DD91007A4DD0 /* ChangePasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC080F1B90DD91007A4DD0 /* ChangePasscodeStateTests.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08121B90DE1B007A4DD0 /* PasscodeSignPlaceholderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08111B90DE1B007A4DD0 /* PasscodeSignPlaceholderView.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08141B90DE50007A4DD0 /* PasscodeSignButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08131B90DE50007A4DD0 /* PasscodeSignButton.swift */; settings = {ASSET_TAGS = (); }; }; - C9DC08161B90DF4E007A4DD0 /* PasscodeLockViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08151B90DF4E007A4DD0 /* PasscodeLockViewController.swift */; settings = {ASSET_TAGS = (); }; }; + C9DC07EA1B90C690007A4DD0 /* FakePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07E91B90C690007A4DD0 /* FakePasscodeState.swift */; }; + C9DC07EC1B90C72A007A4DD0 /* FakePasscodeRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07EB1B90C72A007A4DD0 /* FakePasscodeRepository.swift */; }; + C9DC07EE1B90C7CD007A4DD0 /* FakePasscodeLockConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07ED1B90C7CD007A4DD0 /* FakePasscodeLockConfiguration.swift */; }; + C9DC07F01B90C8E1007A4DD0 /* FakePasscodeLockDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07EF1B90C8E1007A4DD0 /* FakePasscodeLockDelegate.swift */; }; + C9DC07F21B90C9DE007A4DD0 /* EnterPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F11B90C9DE007A4DD0 /* EnterPasscodeState.swift */; }; + C9DC07F31B90C9DE007A4DD0 /* EnterPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F11B90C9DE007A4DD0 /* EnterPasscodeState.swift */; }; + C9DC07F81B90CF29007A4DD0 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F71B90CF29007A4DD0 /* Functions.swift */; }; + C9DC07F91B90CF29007A4DD0 /* Functions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07F71B90CF29007A4DD0 /* Functions.swift */; }; + C9DC07FC1B90D0A3007A4DD0 /* PasscodeLock.strings in Resources */ = {isa = PBXBuildFile; fileRef = C9DC07FA1B90D0A3007A4DD0 /* PasscodeLock.strings */; }; + C9DC07FD1B90D0A3007A4DD0 /* PasscodeLock.strings in Resources */ = {isa = PBXBuildFile; fileRef = C9DC07FA1B90D0A3007A4DD0 /* PasscodeLock.strings */; }; + C9DC07FF1B90D24A007A4DD0 /* SetPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07FE1B90D24A007A4DD0 /* SetPasscodeState.swift */; }; + C9DC08001B90D24A007A4DD0 /* SetPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC07FE1B90D24A007A4DD0 /* SetPasscodeState.swift */; }; + C9DC08021B90D2BA007A4DD0 /* ConfirmPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08011B90D2BA007A4DD0 /* ConfirmPasscodeState.swift */; }; + C9DC08031B90D2BA007A4DD0 /* ConfirmPasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08011B90D2BA007A4DD0 /* ConfirmPasscodeState.swift */; }; + C9DC08051B90D394007A4DD0 /* ChangePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08041B90D394007A4DD0 /* ChangePasscodeState.swift */; }; + C9DC08061B90D394007A4DD0 /* ChangePasscodeState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08041B90D394007A4DD0 /* ChangePasscodeState.swift */; }; + C9DC08081B90DAE6007A4DD0 /* EnterPasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08071B90DAE6007A4DD0 /* EnterPasscodeStateTests.swift */; }; + C9DC080A1B90DB09007A4DD0 /* FakePasscodeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08091B90DB09007A4DD0 /* FakePasscodeLock.swift */; }; + C9DC080C1B90DC38007A4DD0 /* SetPasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC080B1B90DC38007A4DD0 /* SetPasscodeStateTests.swift */; }; + C9DC080E1B90DC8F007A4DD0 /* ConfirmPasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC080D1B90DC8F007A4DD0 /* ConfirmPasscodeStateTests.swift */; }; + C9DC08101B90DD91007A4DD0 /* ChangePasscodeStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC080F1B90DD91007A4DD0 /* ChangePasscodeStateTests.swift */; }; + C9DC08121B90DE1B007A4DD0 /* PasscodeSignPlaceholderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08111B90DE1B007A4DD0 /* PasscodeSignPlaceholderView.swift */; }; + C9DC08141B90DE50007A4DD0 /* PasscodeSignButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08131B90DE50007A4DD0 /* PasscodeSignButton.swift */; }; + C9DC08161B90DF4E007A4DD0 /* PasscodeLockViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DC08151B90DF4E007A4DD0 /* PasscodeLockViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -457,6 +457,7 @@ }; C9D3DF0F1B91AD11008561EB = { CreatedOnToolsVersion = 7.0; + DevelopmentTeam = 8DA225EN79; }; C9D3DF221B91AD11008561EB = { CreatedOnToolsVersion = 7.0; @@ -473,6 +474,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -703,6 +705,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -743,6 +746,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -765,6 +769,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -782,6 +787,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.yankodimitrov.PasscodeLock; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -789,12 +795,14 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = PasscodeLockTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.yankodimitrov.PasscodeLockTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PasscodeLockTests/PasscodeLockTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -802,11 +810,13 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = PasscodeLockTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.yankodimitrov.PasscodeLockTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PasscodeLockTests/PasscodeLockTests-Bridging-Header.h"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -814,12 +824,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 8DA225EN79; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = PasscodeLockDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.yankodimitrov.PasscodeLockDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -828,12 +840,14 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 8DA225EN79; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = PasscodeLockDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.yankodimitrov.PasscodeLockDemo; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/PasscodeLock/Functions.swift b/PasscodeLock/Functions.swift old mode 100644 new mode 100755 index adb03903..173caf16 --- a/PasscodeLock/Functions.swift +++ b/PasscodeLock/Functions.swift @@ -8,7 +8,7 @@ import Foundation -func localizedStringFor(key: String, comment: String) -> String { +func localizedStringFor(_ key: String, comment: String) -> String { let name = "PasscodeLock" let bundle = bundleForResource(name, ofType: "strings") @@ -16,11 +16,11 @@ func localizedStringFor(key: String, comment: String) -> String { return NSLocalizedString(key, tableName: name, bundle: bundle, comment: comment) } -func bundleForResource(name: String, ofType type: String) -> NSBundle { +func bundleForResource(_ name: String, ofType type: String) -> Bundle { - if(NSBundle.mainBundle().pathForResource(name, ofType: type) != nil) { - return NSBundle.mainBundle() + if(Bundle.main.path(forResource: name, ofType: type) != nil) { + return Bundle.main } - return NSBundle(forClass: PasscodeLock.self) + return Bundle(for: PasscodeLock.self) } diff --git a/PasscodeLock/Info.plist b/PasscodeLock/Info.plist old mode 100644 new mode 100755 diff --git a/PasscodeLock/PasscodeLock.h b/PasscodeLock/PasscodeLock.h old mode 100644 new mode 100755 diff --git a/PasscodeLock/PasscodeLock/ChangePasscodeState.swift b/PasscodeLock/PasscodeLock/ChangePasscodeState.swift old mode 100644 new mode 100755 index 1106f145..aefaacae --- a/PasscodeLock/PasscodeLock/ChangePasscodeState.swift +++ b/PasscodeLock/PasscodeLock/ChangePasscodeState.swift @@ -21,7 +21,7 @@ struct ChangePasscodeState: PasscodeLockStateType { description = localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description") } - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) { + func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType) { guard let currentPasscode = lock.repository.passcode else { return diff --git a/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift b/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift old mode 100644 new mode 100755 index c6683cea..371562b5 --- a/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift +++ b/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift @@ -15,7 +15,7 @@ struct ConfirmPasscodeState: PasscodeLockStateType { let isCancellableAction = true var isTouchIDAllowed = false - private var passcodeToConfirm: [String] + fileprivate var passcodeToConfirm: [String] init(passcode: [String]) { @@ -24,7 +24,7 @@ struct ConfirmPasscodeState: PasscodeLockStateType { description = localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description") } - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) { + func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType) { if passcode == passcodeToConfirm { diff --git a/PasscodeLock/PasscodeLock/EnterPasscodeState.swift b/PasscodeLock/PasscodeLock/EnterPasscodeState.swift old mode 100644 new mode 100755 index 60f58bc8..ebf8d2ec --- a/PasscodeLock/PasscodeLock/EnterPasscodeState.swift +++ b/PasscodeLock/PasscodeLock/EnterPasscodeState.swift @@ -17,7 +17,16 @@ struct EnterPasscodeState: PasscodeLockStateType { let isCancellableAction: Bool var isTouchIDAllowed = true - private var inccorectPasscodeAttempts = 0 + static let incorrectPasscodeAttemptsKey = "incorrectPasscodeAttempts" + static var incorrectPasscodeAttempts: Int { + get { + return UserDefaults.standard.integer(forKey: incorrectPasscodeAttemptsKey) + } + set { + UserDefaults.standard.set(newValue, forKey: incorrectPasscodeAttemptsKey) + } + } + private var isNotificationSent = false init(allowCancellation: Bool = false) { @@ -27,36 +36,40 @@ struct EnterPasscodeState: PasscodeLockStateType { description = localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description") } - mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) { + mutating func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType) { guard let currentPasscode = lock.repository.passcode else { return } + var incorrectPasscodeAttempts = EnterPasscodeState.incorrectPasscodeAttempts if passcode == currentPasscode { lock.delegate?.passcodeLockDidSucceed(lock) - + incorrectPasscodeAttempts = 0 } else { - inccorectPasscodeAttempts += 1 + incorrectPasscodeAttempts += 1 - if inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts { + if incorrectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts { postNotification() + incorrectPasscodeAttempts = 0 } lock.delegate?.passcodeLockDidFail(lock) } + + EnterPasscodeState.incorrectPasscodeAttempts = incorrectPasscodeAttempts } - private mutating func postNotification() { + fileprivate mutating func postNotification() { guard !isNotificationSent else { return } - let center = NSNotificationCenter.defaultCenter() + let center = NotificationCenter.default - center.postNotificationName(PasscodeLockIncorrectPasscodeNotification, object: nil) + center.post(name: Notification.Name(rawValue: PasscodeLockIncorrectPasscodeNotification), object: nil) isNotificationSent = true } diff --git a/PasscodeLock/PasscodeLock/PasscodeLock.swift b/PasscodeLock/PasscodeLock/PasscodeLock.swift old mode 100644 new mode 100755 index a6ca8372..595d0d38 --- a/PasscodeLock/PasscodeLock/PasscodeLock.swift +++ b/PasscodeLock/PasscodeLock/PasscodeLock.swift @@ -9,25 +9,25 @@ import Foundation import LocalAuthentication -public class PasscodeLock: PasscodeLockType { +open class PasscodeLock: PasscodeLockType { - public weak var delegate: PasscodeLockTypeDelegate? + open weak var delegate: PasscodeLockTypeDelegate? public let configuration: PasscodeLockConfigurationType - public var repository: PasscodeRepositoryType { + open var repository: PasscodeRepositoryType { return configuration.repository } - public var state: PasscodeLockStateType { + open var state: PasscodeLockStateType { return lockState } - public var isTouchIDAllowed: Bool { + open var isTouchIDAllowed: Bool { return isTouchIDEnabled() && configuration.isTouchIDAllowed && lockState.isTouchIDAllowed } - private var lockState: PasscodeLockStateType - private lazy var passcode = [String]() + fileprivate var lockState: PasscodeLockStateType + fileprivate lazy var passcode = [String]() public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType) { @@ -37,19 +37,21 @@ public class PasscodeLock: PasscodeLockType { self.configuration = configuration } - public func addSign(sign: String) { + open func addSign(_ sign: String) { passcode.append(sign) delegate?.passcodeLock(self, addedSignAtIndex: passcode.count - 1) if passcode.count >= configuration.passcodeLength { - lockState.acceptPasscode(passcode, fromLock: self) - passcode.removeAll(keepCapacity: true) + // handles "requires exclusive access" error at Swift 4 + var lockStateCopy = lockState + lockStateCopy.acceptPasscode(passcode, fromLock: self) + passcode.removeAll(keepingCapacity: true) } } - public func removeSign() { + open func removeSign() { guard passcode.count > 0 else { return } @@ -57,43 +59,48 @@ public class PasscodeLock: PasscodeLockType { delegate?.passcodeLock(self, removedSignAtIndex: passcode.count) } - public func changeStateTo(state: PasscodeLockStateType) { + open func changeStateTo(_ state: PasscodeLockStateType) { lockState = state delegate?.passcodeLockDidChangeState(self) } - public func authenticateWithBiometrics() { + open func authenticateWithBiometrics() { guard isTouchIDAllowed else { return } let context = LAContext() - let reason = localizedStringFor("PasscodeLockTouchIDReason", comment: "TouchID authentication reason") + let reason: String + if let configReason = configuration.touchIdReason { + reason = configReason + } else { + reason = localizedStringFor("PasscodeLockTouchIDReason", comment: "TouchID authentication reason") + } context.localizedFallbackTitle = localizedStringFor("PasscodeLockTouchIDButton", comment: "TouchID authentication fallback button") - context.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { + context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, error in self.handleTouchIDResult(success) } } - private func handleTouchIDResult(success: Bool) { + fileprivate func handleTouchIDResult(_ success: Bool) { - dispatch_async(dispatch_get_main_queue()) { + DispatchQueue.main.async { if success { - + EnterPasscodeState.incorrectPasscodeAttempts = 0 self.delegate?.passcodeLockDidSucceed(self) } } } - private func isTouchIDEnabled() -> Bool { + fileprivate func isTouchIDEnabled() -> Bool { let context = LAContext() - return context.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil) + return context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) } } diff --git a/PasscodeLock/PasscodeLock/SetPasscodeState.swift b/PasscodeLock/PasscodeLock/SetPasscodeState.swift old mode 100644 new mode 100755 index f4a96be9..b43e4bbb --- a/PasscodeLock/PasscodeLock/SetPasscodeState.swift +++ b/PasscodeLock/PasscodeLock/SetPasscodeState.swift @@ -27,7 +27,7 @@ struct SetPasscodeState: PasscodeLockStateType { description = localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description") } - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) { + func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType) { let nextState = ConfirmPasscodeState(passcode: passcode) diff --git a/PasscodeLock/PasscodeLockPresenter.swift b/PasscodeLock/PasscodeLockPresenter.swift old mode 100644 new mode 100755 index c2ac3d6d..a0be9cdc --- a/PasscodeLock/PasscodeLockPresenter.swift +++ b/PasscodeLock/PasscodeLockPresenter.swift @@ -8,54 +8,66 @@ import UIKit -public class PasscodeLockPresenter { +open class PasscodeLockPresenter { - private var mainWindow: UIWindow? + fileprivate var mainWindow: UIWindow? - private lazy var passcodeLockWindow: UIWindow = { + fileprivate lazy var passcodeLockWindow: UIWindow = { - let window = UIWindow(frame: UIScreen.mainScreen().bounds) + let window = UIWindow(frame: UIScreen.main.bounds) - window.windowLevel = 0 + window.windowLevel = UIWindow.Level(rawValue: 0) window.makeKeyAndVisible() return window }() - private let passcodeConfiguration: PasscodeLockConfigurationType - public var isPasscodePresented = false + fileprivate let passcodeConfiguration: PasscodeLockConfigurationType + open var isPasscodePresented = false + public let passcodeLockVC: PasscodeLockViewController public init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, viewController: PasscodeLockViewController) { mainWindow = window - mainWindow?.windowLevel = 1 + mainWindow?.windowLevel = UIWindow.Level(rawValue: 1) passcodeConfiguration = configuration passcodeLockVC = viewController } public convenience init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType) { - - let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: configuration) + let passcodeLockVC = PasscodeLockViewController(state: .enterPasscode, configuration: configuration) self.init(mainWindow: window, configuration: configuration, viewController: passcodeLockVC) } - public func presentPasscodeLock() { + // HACK: below function that handles not presenting the keyboard in case Passcode is presented + // is a smell in the code that had to be introduced for iOS9 where Apple decided to move the keyboard + // in a UIRemoteKeyboardWindow. + // This doesn't allow our Passcode Lock window to move on top of keyboard. + // Setting a higher windowLevel to our window or even trying to change keyboards' + // windowLevel has been tried without luck. + // + // Revise in a later version and remove the hack if not needed + func toggleKeyboardVisibility(hide: Bool) { + if let keyboardWindow = UIApplication.shared.windows.last, + keyboardWindow.description.hasPrefix(" PasscodeLockStateType { switch self { - case .EnterPasscode: return EnterPasscodeState() - case .SetPasscode: return SetPasscodeState() - case .ChangePasscode: return ChangePasscodeState() - case .RemovePasscode: return EnterPasscodeState(allowCancellation: true) + case .enterPasscode: return EnterPasscodeState() + case .setPasscode: return SetPasscodeState() + case .changePasscode: return ChangePasscodeState() + case .removePasscode: return EnterPasscodeState(allowCancellation: true) } } } - @IBOutlet public weak var titleLabel: UILabel? - @IBOutlet public weak var descriptionLabel: UILabel? - @IBOutlet public var placeholders: [PasscodeSignPlaceholderView] = [PasscodeSignPlaceholderView]() - @IBOutlet public weak var cancelButton: UIButton? - @IBOutlet public weak var deleteSignButton: UIButton? - @IBOutlet public weak var touchIDButton: UIButton? - @IBOutlet public weak var placeholdersX: NSLayoutConstraint? + @IBOutlet open weak var titleLabel: UILabel? + @IBOutlet open weak var descriptionLabel: UILabel? + @IBOutlet open var placeholders: [PasscodeSignPlaceholderView] = [PasscodeSignPlaceholderView]() + @IBOutlet open weak var cancelButton: UIButton? + @IBOutlet open weak var deleteSignButton: UIButton? + @IBOutlet open weak var touchIDButton: UIButton? + @IBOutlet open weak var placeholdersX: NSLayoutConstraint? - public var successCallback: ((lock: PasscodeLockType) -> Void)? - public var dismissCompletionCallback: (()->Void)? - public var animateOnDismiss: Bool - public var notificationCenter: NSNotificationCenter? + open var successCallback: ((_ lock: PasscodeLockType) -> Void)? + open var dismissCompletionCallback: (()->Void)? + open var animateOnDismiss: Bool + open var notificationCenter: NotificationCenter? internal let passcodeConfiguration: PasscodeLockConfigurationType - internal let passcodeLock: PasscodeLockType + internal var passcodeLock: PasscodeLockType internal var isPlaceholdersAnimationCompleted = true - private var shouldTryToAuthenticateWithBiometrics = true + fileprivate var shouldTryToAuthenticateWithBiometrics = true // MARK: - Initializers - public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true) { + public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, nibName: String = "PasscodeLockView", bundle: Bundle? = nil) { self.animateOnDismiss = animateOnDismiss passcodeConfiguration = configuration passcodeLock = PasscodeLock(state: state, configuration: configuration) - let nibName = "PasscodeLockView" - let bundle: NSBundle = bundleForResource(nibName, ofType: "nib") + let bundleToUse = bundle ?? bundleForResource(nibName, ofType: "nib") - super.init(nibName: nibName, bundle: bundle) + super.init(nibName: nibName, bundle: bundleToUse) passcodeLock.delegate = self - notificationCenter = NSNotificationCenter.defaultCenter() + notificationCenter = NotificationCenter.default } public convenience init(state: LockState, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true) { @@ -80,19 +79,24 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg // MARK: - View - public override func viewDidLoad() { + open override func viewDidLoad() { super.viewDidLoad() - updatePasscodeView() - deleteSignButton?.enabled = false + deleteSignButton?.isEnabled = false setupEvents() } - public override func viewDidAppear(animated: Bool) { + open override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + updatePasscodeView() + } + + open override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - if shouldTryToAuthenticateWithBiometrics { + if shouldTryToAuthenticateWithBiometrics && passcodeConfiguration.shouldRequestTouchIDImmediately { authenticateWithBiometrics() } @@ -102,72 +106,76 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg titleLabel?.text = passcodeLock.state.title descriptionLabel?.text = passcodeLock.state.description - cancelButton?.hidden = !passcodeLock.state.isCancellableAction - touchIDButton?.hidden = !passcodeLock.isTouchIDAllowed + cancelButton?.isHidden = !passcodeLock.state.isCancellableAction + touchIDButton?.isHidden = !passcodeLock.isTouchIDAllowed } // MARK: - Events - private func setupEvents() { + fileprivate func setupEvents() { - notificationCenter?.addObserver(self, selector: "appWillEnterForegroundHandler:", name: UIApplicationWillEnterForegroundNotification, object: nil) - notificationCenter?.addObserver(self, selector: "appDidEnterBackgroundHandler:", name: UIApplicationDidEnterBackgroundNotification, object: nil) + notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appWillEnterForegroundHandler(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) + notificationCenter?.addObserver(self, selector: #selector(PasscodeLockViewController.appDidEnterBackgroundHandler(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil) } - private func clearEvents() { + fileprivate func clearEvents() { - notificationCenter?.removeObserver(self, name: UIApplicationWillEnterForegroundNotification, object: nil) - notificationCenter?.removeObserver(self, name: UIApplicationDidEnterBackgroundNotification, object: nil) + notificationCenter?.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil) + notificationCenter?.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil) } - public func appWillEnterForegroundHandler(notification: NSNotification) { + @objc open func appWillEnterForegroundHandler(_ notification: Notification) { - authenticateWithBiometrics() + if passcodeConfiguration.shouldRequestTouchIDImmediately { + authenticateWithBiometrics() + } } - public func appDidEnterBackgroundHandler(notification: NSNotification) { + @objc open func appDidEnterBackgroundHandler(_ notification: Notification) { shouldTryToAuthenticateWithBiometrics = false } // MARK: - Actions - @IBAction func passcodeSignButtonTap(sender: PasscodeSignButton) { + @IBAction func passcodeSignButtonTap(_ sender: PasscodeSignButton) { guard isPlaceholdersAnimationCompleted else { return } passcodeLock.addSign(sender.passcodeSign) } - @IBAction func cancelButtonTap(sender: UIButton) { + @IBAction func cancelButtonTap(_ sender: UIButton) { dismissPasscodeLock(passcodeLock) } - @IBAction func deleteSignButtonTap(sender: UIButton) { + @IBAction func deleteSignButtonTap(_ sender: UIButton) { passcodeLock.removeSign() } - @IBAction func touchIDButtonTap(sender: UIButton) { + @IBAction func touchIDButtonTap(_ sender: UIButton) { passcodeLock.authenticateWithBiometrics() } - private func authenticateWithBiometrics() { + open func authenticateWithBiometrics() { - if passcodeConfiguration.shouldRequestTouchIDImmediately && passcodeLock.isTouchIDAllowed { + guard passcodeConfiguration.repository.hasPasscode else { return } + + if passcodeLock.isTouchIDAllowed { passcodeLock.authenticateWithBiometrics() } } - internal func dismissPasscodeLock(lock: PasscodeLockType, completionHandler: (() -> Void)? = nil) { + internal func dismissPasscodeLock(_ lock: PasscodeLockType, completionHandler: (() -> Void)? = nil) { // if presented as modal if presentingViewController?.presentedViewController == self { - dismissViewControllerAnimated(animateOnDismiss, completion: { [weak self] _ in + dismiss(animated: animateOnDismiss, completion: { [weak self] in self?.dismissCompletionCallback?() @@ -178,8 +186,8 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg // if pushed in a navigation controller } else if navigationController != nil { - - navigationController?.popViewControllerAnimated(animateOnDismiss) + + navigationController?.popViewController(animated: animateOnDismiss) } dismissCompletionCallback?() @@ -191,16 +199,16 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg internal func animateWrongPassword() { - deleteSignButton?.enabled = false + deleteSignButton?.isEnabled = false isPlaceholdersAnimationCompleted = false - animatePlaceholders(placeholders, toState: .Error) + animatePlaceholders(placeholders, toState: .error) placeholdersX?.constant = -40 view.layoutIfNeeded() - UIView.animateWithDuration( - 0.5, + UIView.animate( + withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 0, @@ -213,11 +221,11 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg completion: { completed in self.isPlaceholdersAnimationCompleted = true - self.animatePlaceholders(self.placeholders, toState: .Inactive) + self.animatePlaceholders(self.placeholders, toState: .inactive) }) } - internal func animatePlaceholders(placeholders: [PasscodeSignPlaceholderView], toState state: PasscodeSignPlaceholderView.State) { + internal func animatePlaceholders(_ placeholders: [PasscodeSignPlaceholderView], toState state: PasscodeSignPlaceholderView.State) { for placeholder in placeholders { @@ -225,7 +233,7 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg } } - private func animatePlacehodlerAtIndex(index: Int, toState state: PasscodeSignPlaceholderView.State) { + fileprivate func animatePlacehodlerAtIndex(_ index: Int, toState state: PasscodeSignPlaceholderView.State) { guard index < placeholders.count && index >= 0 else { return } @@ -234,40 +242,40 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg // MARK: - PasscodeLockDelegate - public func passcodeLockDidSucceed(lock: PasscodeLockType) { + open func passcodeLockDidSucceed(_ lock: PasscodeLockType) { - deleteSignButton?.enabled = true - animatePlaceholders(placeholders, toState: .Inactive) - dismissPasscodeLock(lock, completionHandler: { [weak self] _ in - self?.successCallback?(lock: lock) + deleteSignButton?.isEnabled = true + animatePlaceholders(placeholders, toState: .inactive) + dismissPasscodeLock(lock, completionHandler: { [weak self] in + self?.successCallback?(lock) }) } - public func passcodeLockDidFail(lock: PasscodeLockType) { + open func passcodeLockDidFail(_ lock: PasscodeLockType) { animateWrongPassword() } - public func passcodeLockDidChangeState(lock: PasscodeLockType) { + open func passcodeLockDidChangeState(_ lock: PasscodeLockType) { updatePasscodeView() - animatePlaceholders(placeholders, toState: .Inactive) - deleteSignButton?.enabled = false + animatePlaceholders(placeholders, toState: .inactive) + deleteSignButton?.isEnabled = false } - public func passcodeLock(lock: PasscodeLockType, addedSignAtIndex index: Int) { + open func passcodeLock(_ lock: PasscodeLockType, addedSignAtIndex index: Int) { - animatePlacehodlerAtIndex(index, toState: .Active) - deleteSignButton?.enabled = true + animatePlacehodlerAtIndex(index, toState: .active) + deleteSignButton?.isEnabled = true } - public func passcodeLock(lock: PasscodeLockType, removedSignAtIndex index: Int) { + open func passcodeLock(_ lock: PasscodeLockType, removedSignAtIndex index: Int) { - animatePlacehodlerAtIndex(index, toState: .Inactive) + animatePlacehodlerAtIndex(index, toState: .inactive) if index == 0 { - deleteSignButton?.enabled = false + deleteSignButton?.isEnabled = false } } } diff --git a/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift b/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift old mode 100644 new mode 100755 index af4c27c1..26daee2c --- a/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift +++ b/PasscodeLock/Protocols/PasscodeLockConfigurationType.swift @@ -14,5 +14,17 @@ public protocol PasscodeLockConfigurationType { var passcodeLength: Int {get} var isTouchIDAllowed: Bool {get set} var shouldRequestTouchIDImmediately: Bool {get} + var touchIdReason: String? {get set} var maximumInccorectPasscodeAttempts: Int {get} } + +// set configuration optionals +public extension PasscodeLockConfigurationType { + var passcodeLength: Int { + return 4 + } + + var maximumInccorectPasscodeAttempts: Int { + return -1 + } +} diff --git a/PasscodeLock/Protocols/PasscodeLockStateType.swift b/PasscodeLock/Protocols/PasscodeLockStateType.swift old mode 100644 new mode 100755 index d9725f15..f246e2d9 --- a/PasscodeLock/Protocols/PasscodeLockStateType.swift +++ b/PasscodeLock/Protocols/PasscodeLockStateType.swift @@ -15,5 +15,5 @@ public protocol PasscodeLockStateType { var isCancellableAction: Bool {get} var isTouchIDAllowed: Bool {get} - mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) + mutating func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType) } diff --git a/PasscodeLock/Protocols/PasscodeLockType.swift b/PasscodeLock/Protocols/PasscodeLockType.swift old mode 100644 new mode 100755 index e236b05c..c5390112 --- a/PasscodeLock/Protocols/PasscodeLockType.swift +++ b/PasscodeLock/Protocols/PasscodeLockType.swift @@ -10,23 +10,23 @@ import Foundation public protocol PasscodeLockType { - weak var delegate: PasscodeLockTypeDelegate? {get set} + var delegate: PasscodeLockTypeDelegate? {get set} var configuration: PasscodeLockConfigurationType {get} var repository: PasscodeRepositoryType {get} var state: PasscodeLockStateType {get} var isTouchIDAllowed: Bool {get} - func addSign(sign: String) + func addSign(_ sign: String) func removeSign() - func changeStateTo(state: PasscodeLockStateType) + func changeStateTo(_ state: PasscodeLockStateType) func authenticateWithBiometrics() } public protocol PasscodeLockTypeDelegate: class { - func passcodeLockDidSucceed(lock: PasscodeLockType) - func passcodeLockDidFail(lock: PasscodeLockType) - func passcodeLockDidChangeState(lock: PasscodeLockType) - func passcodeLock(lock: PasscodeLockType, addedSignAtIndex index: Int) - func passcodeLock(lock: PasscodeLockType, removedSignAtIndex index: Int) + func passcodeLockDidSucceed(_ lock: PasscodeLockType) + func passcodeLockDidFail(_ lock: PasscodeLockType) + func passcodeLockDidChangeState(_ lock: PasscodeLockType) + func passcodeLock(_ lock: PasscodeLockType, addedSignAtIndex index: Int) + func passcodeLock(_ lock: PasscodeLockType, removedSignAtIndex index: Int) } diff --git a/PasscodeLock/Protocols/PasscodeRepositoryType.swift b/PasscodeLock/Protocols/PasscodeRepositoryType.swift old mode 100644 new mode 100755 index 19272379..79475434 --- a/PasscodeLock/Protocols/PasscodeRepositoryType.swift +++ b/PasscodeLock/Protocols/PasscodeRepositoryType.swift @@ -13,6 +13,6 @@ public protocol PasscodeRepositoryType { var hasPasscode: Bool {get} var passcode: [String]? {get} - func savePasscode(passcode: [String]) + func savePasscode(_ passcode: [String]) func deletePasscode() } diff --git a/PasscodeLock/Views/PasscodeLockView.xib b/PasscodeLock/Views/PasscodeLockView.xib old mode 100644 new mode 100755 index 99620adb..d3cf4121 --- a/PasscodeLock/Views/PasscodeLockView.xib +++ b/PasscodeLock/Views/PasscodeLockView.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -22,86 +26,86 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -116,23 +120,23 @@ - + diff --git a/PasscodeLock/Views/PasscodeSignButton.swift b/PasscodeLock/Views/PasscodeSignButton.swift old mode 100644 new mode 100755 index 9fb3968a..0ed0d7fe --- a/PasscodeLock/Views/PasscodeSignButton.swift +++ b/PasscodeLock/Views/PasscodeSignButton.swift @@ -9,27 +9,27 @@ import UIKit @IBDesignable -public class PasscodeSignButton: UIButton { +open class PasscodeSignButton: UIButton { @IBInspectable - public var passcodeSign: String = "1" + open var passcodeSign: String = "1" @IBInspectable - public var borderColor: UIColor = UIColor.whiteColor() { + open var borderColor: UIColor = UIColor.white { didSet { setupView() } } @IBInspectable - public var borderRadius: CGFloat = 30 { + open var borderRadius: CGFloat = 30 { didSet { setupView() } } @IBInspectable - public var highlightBackgroundColor: UIColor = UIColor.clearColor() { + open var highlightBackgroundColor: UIColor = UIColor.clear { didSet { setupView() } @@ -50,18 +50,18 @@ public class PasscodeSignButton: UIButton { setupActions() } - public override func intrinsicContentSize() -> CGSize { + open override var intrinsicContentSize : CGSize { - return CGSizeMake(60, 60) + return CGSize(width: 60, height: 60) } - private var defaultBackgroundColor = UIColor.clearColor() + fileprivate var defaultBackgroundColor = UIColor.clear - private func setupView() { + fileprivate func setupView() { layer.borderWidth = 1 layer.cornerRadius = borderRadius - layer.borderColor = borderColor.CGColor + layer.borderColor = borderColor.cgColor if let backgroundColor = backgroundColor { @@ -69,30 +69,30 @@ public class PasscodeSignButton: UIButton { } } - private func setupActions() { + fileprivate func setupActions() { - addTarget(self, action: Selector("handleTouchDown"), forControlEvents: .TouchDown) - addTarget(self, action: Selector("handleTouchUp"), forControlEvents: [.TouchUpInside, .TouchDragOutside, .TouchCancel]) + addTarget(self, action: #selector(PasscodeSignButton.handleTouchDown), for: .touchDown) + addTarget(self, action: #selector(PasscodeSignButton.handleTouchUp), for: [.touchUpInside, .touchDragOutside, .touchCancel]) } - func handleTouchDown() { + @objc func handleTouchDown() { animateBackgroundColor(highlightBackgroundColor) } - func handleTouchUp() { + @objc func handleTouchUp() { animateBackgroundColor(defaultBackgroundColor) } - private func animateBackgroundColor(color: UIColor) { + fileprivate func animateBackgroundColor(_ color: UIColor) { - UIView.animateWithDuration( - 0.3, + UIView.animate( + withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0.0, - options: [.AllowUserInteraction, .BeginFromCurrentState], + options: [.allowUserInteraction, .beginFromCurrentState], animations: { self.backgroundColor = color diff --git a/PasscodeLock/Views/PasscodeSignPlaceholderView.swift b/PasscodeLock/Views/PasscodeSignPlaceholderView.swift old mode 100644 new mode 100755 index 953c9ef4..2191a302 --- a/PasscodeLock/Views/PasscodeSignPlaceholderView.swift +++ b/PasscodeLock/Views/PasscodeSignPlaceholderView.swift @@ -9,30 +9,30 @@ import UIKit @IBDesignable -public class PasscodeSignPlaceholderView: UIView { +open class PasscodeSignPlaceholderView: UIView { public enum State { - case Inactive - case Active - case Error + case inactive + case active + case error } @IBInspectable - public var inactiveColor: UIColor = UIColor.whiteColor() { + open var inactiveColor: UIColor = UIColor.white { didSet { setupView() } } @IBInspectable - public var activeColor: UIColor = UIColor.grayColor() { + open var activeColor: UIColor = UIColor.gray { didSet { setupView() } } @IBInspectable - public var errorColor: UIColor = UIColor.redColor() { + open var errorColor: UIColor = UIColor.red { didSet { setupView() } @@ -50,34 +50,34 @@ public class PasscodeSignPlaceholderView: UIView { super.init(coder: aDecoder) } - public override func intrinsicContentSize() -> CGSize { + open override var intrinsicContentSize : CGSize { - return CGSizeMake(16, 16) + return CGSize(width: 16, height: 16) } - private func setupView() { + fileprivate func setupView() { layer.cornerRadius = 8 layer.borderWidth = 1 - layer.borderColor = activeColor.CGColor + layer.borderColor = activeColor.cgColor backgroundColor = inactiveColor } - private func colorsForState(state: State) -> (backgroundColor: UIColor, borderColor: UIColor) { + fileprivate func colorsForState(_ state: State) -> (backgroundColor: UIColor, borderColor: UIColor) { switch state { - case .Inactive: return (inactiveColor, activeColor) - case .Active: return (activeColor, activeColor) - case .Error: return (errorColor, errorColor) + case .inactive: return (inactiveColor, activeColor) + case .active: return (activeColor, activeColor) + case .error: return (errorColor, errorColor) } } - public func animateState(state: State) { + open func animateState(_ state: State) { let colors = colorsForState(state) - UIView.animateWithDuration( - 0.5, + UIView.animate( + withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, @@ -85,7 +85,7 @@ public class PasscodeSignPlaceholderView: UIView { animations: { self.backgroundColor = colors.backgroundColor - self.layer.borderColor = colors.borderColor.CGColor + self.layer.borderColor = colors.borderColor.cgColor }, completion: nil diff --git a/PasscodeLockDemo/AppDelegate.swift b/PasscodeLockDemo/AppDelegate.swift index 2646f914..97948d92 100644 --- a/PasscodeLockDemo/AppDelegate.swift +++ b/PasscodeLockDemo/AppDelegate.swift @@ -22,34 +22,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return presenter }() - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - - passcodeLockPresenter.presentPasscodeLock() - - return true + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { + + passcodeLockPresenter.presentPasscodeLock() + + return true } - - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. passcodeLockPresenter.presentPasscodeLock() } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } } diff --git a/PasscodeLockDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/PasscodeLockDemo/Assets.xcassets/AppIcon.appiconset/Contents.json index 36d2c80d..d8db8d65 100644 --- a/PasscodeLockDemo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/PasscodeLockDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,16 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/PasscodeLockDemo/Assets.xcassets/Contents.json b/PasscodeLockDemo/Assets.xcassets/Contents.json new file mode 100644 index 00000000..da4a164c --- /dev/null +++ b/PasscodeLockDemo/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/PasscodeLockDemo/Base.lproj/Main.storyboard b/PasscodeLockDemo/Base.lproj/Main.storyboard index bea52e36..b4c66957 100644 --- a/PasscodeLockDemo/Base.lproj/Main.storyboard +++ b/PasscodeLockDemo/Base.lproj/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,44 +18,44 @@ - + - + - + - + @@ -60,7 +64,7 @@ - + diff --git a/PasscodeLockDemo/Info.plist b/PasscodeLockDemo/Info.plist index 0ca4d80e..53d83649 100644 --- a/PasscodeLockDemo/Info.plist +++ b/PasscodeLockDemo/Info.plist @@ -2,6 +2,8 @@ + NSFaceIDUsageDescription + Unlock using your face CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/PasscodeLockDemo/PasscodeLockConfiguration.swift b/PasscodeLockDemo/PasscodeLockConfiguration.swift index 5a176bd7..c16baebb 100644 --- a/PasscodeLockDemo/PasscodeLockConfiguration.swift +++ b/PasscodeLockDemo/PasscodeLockConfiguration.swift @@ -10,6 +10,8 @@ import Foundation import PasscodeLock struct PasscodeLockConfiguration: PasscodeLockConfigurationType { + var touchIdReason: String? + let repository: PasscodeRepositoryType let passcodeLength = 4 diff --git a/PasscodeLockDemo/PasscodeSettingsViewController.swift b/PasscodeLockDemo/PasscodeSettingsViewController.swift index 36ac6123..17fc24fc 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) + passcodeVC = PasscodeLockViewController(state: .setPasscode, configuration: configuration) } else { - passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration) + passcodeVC = PasscodeLockViewController(state: .removePasscode, configuration: configuration) 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) + let passcodeLock = PasscodeLockViewController(state: .changePasscode, configuration: config) - 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/PasscodeLockDemoTests/Info.plist b/PasscodeLockDemoTests/Info.plist old mode 100644 new mode 100755 diff --git a/PasscodeLockDemoUITests/Info.plist b/PasscodeLockDemoUITests/Info.plist old mode 100644 new mode 100755 diff --git a/PasscodeLockTests/Fakes/FakePasscodeLock.swift b/PasscodeLockTests/Fakes/FakePasscodeLock.swift old mode 100644 new mode 100755 index 518710e3..8975eaa9 --- a/PasscodeLockTests/Fakes/FakePasscodeLock.swift +++ b/PasscodeLockTests/Fakes/FakePasscodeLock.swift @@ -25,7 +25,7 @@ class FakePasscodeLock: PasscodeLockType { self.configuration = configuration } - func addSign(sign: String) { + func addSign(_ sign: String) { } @@ -33,7 +33,7 @@ class FakePasscodeLock: PasscodeLockType { } - func changeStateTo(state: PasscodeLockStateType) { + func changeStateTo(_ state: PasscodeLockStateType) { lockState = state changeStateCalled = true diff --git a/PasscodeLockTests/Fakes/FakePasscodeLockConfiguration.swift b/PasscodeLockTests/Fakes/FakePasscodeLockConfiguration.swift old mode 100644 new mode 100755 index 1cae5788..eac9d142 --- a/PasscodeLockTests/Fakes/FakePasscodeLockConfiguration.swift +++ b/PasscodeLockTests/Fakes/FakePasscodeLockConfiguration.swift @@ -11,10 +11,10 @@ import Foundation class FakePasscodeLockConfiguration: PasscodeLockConfigurationType { let repository: PasscodeRepositoryType - let passcodeLength = 4 var isTouchIDAllowed = false let maximumInccorectPasscodeAttempts = 3 let shouldRequestTouchIDImmediately = false + var touchIdReason: String? = nil init(repository: PasscodeRepositoryType) { diff --git a/PasscodeLockTests/Fakes/FakePasscodeLockDelegate.swift b/PasscodeLockTests/Fakes/FakePasscodeLockDelegate.swift old mode 100644 new mode 100755 index 3d82b9bf..72d4b85a --- a/PasscodeLockTests/Fakes/FakePasscodeLockDelegate.swift +++ b/PasscodeLockTests/Fakes/FakePasscodeLockDelegate.swift @@ -10,9 +10,9 @@ import Foundation class FakePasscodeLockDelegate: PasscodeLockTypeDelegate { - func passcodeLockDidSucceed(lock: PasscodeLockType) {} - func passcodeLockDidFail(lock: PasscodeLockType) {} - func passcodeLockDidChangeState(lock: PasscodeLockType) {} - func passcodeLock(lock: PasscodeLockType, addedSignAtIndex index: Int) {} - func passcodeLock(lock: PasscodeLockType, removedSignAtIndex index: Int) {} + func passcodeLockDidSucceed(_ lock: PasscodeLockType) {} + func passcodeLockDidFail(_ lock: PasscodeLockType) {} + func passcodeLockDidChangeState(_ lock: PasscodeLockType) {} + func passcodeLock(_ lock: PasscodeLockType, addedSignAtIndex index: Int) {} + func passcodeLock(_ lock: PasscodeLockType, removedSignAtIndex index: Int) {} } diff --git a/PasscodeLockTests/Fakes/FakePasscodeRepository.swift b/PasscodeLockTests/Fakes/FakePasscodeRepository.swift old mode 100644 new mode 100755 index 657b67fc..9c210521 --- a/PasscodeLockTests/Fakes/FakePasscodeRepository.swift +++ b/PasscodeLockTests/Fakes/FakePasscodeRepository.swift @@ -18,7 +18,7 @@ class FakePasscodeRepository: PasscodeRepositoryType { var savePasscodeCalled = false var savedPasscode = [String]() - func savePasscode(passcode: [String]) { + func savePasscode(_ passcode: [String]) { savePasscodeCalled = true savedPasscode = passcode diff --git a/PasscodeLockTests/Fakes/FakePasscodeState.swift b/PasscodeLockTests/Fakes/FakePasscodeState.swift old mode 100644 new mode 100755 index 61bc3e3c..b51cee16 --- a/PasscodeLockTests/Fakes/FakePasscodeState.swift +++ b/PasscodeLockTests/Fakes/FakePasscodeState.swift @@ -10,9 +10,9 @@ import Foundation class FakePasscodeState: PasscodeLockStateType { - var title = "A" - var description = "B" - var isCancellableAction = true + let title = "A" + let description = "B" + let isCancellableAction = true var isTouchIDAllowed = true var acceptPaccodeCalled = false @@ -21,7 +21,7 @@ class FakePasscodeState: PasscodeLockStateType { init() {} - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) { + func acceptPasscode(_ passcode: [String], fromLock lock: PasscodeLockType) { acceptedPasscode = passcode acceptPaccodeCalled = true diff --git a/PasscodeLockTests/Info.plist b/PasscodeLockTests/Info.plist old mode 100644 new mode 100755 index ba72822e..48946dfb --- a/PasscodeLockTests/Info.plist +++ b/PasscodeLockTests/Info.plist @@ -2,6 +2,8 @@ + NSFaceIDUsageDescription + Show me your face CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/PasscodeLockTests/PasscodeLock/ChangePasscodeStateTests.swift b/PasscodeLockTests/PasscodeLock/ChangePasscodeStateTests.swift old mode 100644 new mode 100755 index eade20ca..721b5ce5 --- a/PasscodeLockTests/PasscodeLock/ChangePasscodeStateTests.swift +++ b/PasscodeLockTests/PasscodeLock/ChangePasscodeStateTests.swift @@ -31,7 +31,7 @@ class ChangePasscodeStateTests: XCTestCase { var didChangedState = false - override func passcodeLockDidChangeState(lock: PasscodeLockType) { + override func passcodeLockDidChangeState(_ lock: PasscodeLockType) { didChangedState = true } @@ -52,7 +52,7 @@ class ChangePasscodeStateTests: XCTestCase { var called = false - override func passcodeLockDidFail(lock: PasscodeLockType) { + override func passcodeLockDidFail(_ lock: PasscodeLockType) { called = true } diff --git a/PasscodeLockTests/PasscodeLock/ConfirmPasscodeStateTests.swift b/PasscodeLockTests/PasscodeLock/ConfirmPasscodeStateTests.swift old mode 100644 new mode 100755 index f122f702..47b9dfbc --- a/PasscodeLockTests/PasscodeLock/ConfirmPasscodeStateTests.swift +++ b/PasscodeLockTests/PasscodeLock/ConfirmPasscodeStateTests.swift @@ -32,7 +32,7 @@ class ConfirmPasscodeStateTests: XCTestCase { var called = false - override func passcodeLockDidSucceed(lock: PasscodeLockType) { + override func passcodeLockDidSucceed(_ lock: PasscodeLockType) { called = true } @@ -61,12 +61,12 @@ class ConfirmPasscodeStateTests: XCTestCase { var didFailed = false var didChangedState = false - override func passcodeLockDidFail(lock: PasscodeLockType) { + override func passcodeLockDidFail(_ lock: PasscodeLockType) { didFailed = true } - override func passcodeLockDidChangeState(lock: PasscodeLockType) { + override func passcodeLockDidChangeState(_ lock: PasscodeLockType) { didChangedState = true } diff --git a/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift b/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift old mode 100644 new mode 100755 index 2e4dcf94..5aa7e68d --- a/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift +++ b/PasscodeLockTests/PasscodeLock/EnterPasscodeStateTests.swift @@ -15,12 +15,12 @@ class NotificaionObserver: NSObject { func observe(notification: String) { - let center = NSNotificationCenter.defaultCenter() + let center = NotificationCenter.default - center.addObserver(self, selector: "handle:", name: notification, object: nil) + center.addObserver(self, selector: #selector(NotificaionObserver.handle(notification:)), name: NSNotification.Name(rawValue: notification), object: nil) } - func handle(notification: NSNotification) { + @objc func handle(notification: NSNotification) { called = true callCounter += 1 @@ -50,7 +50,7 @@ class EnterPasscodeStateTests: XCTestCase { var called = false - override func passcodeLockDidSucceed(lock: PasscodeLockType) { + override func passcodeLockDidSucceed(_ lock: PasscodeLockType) { called = true } @@ -70,7 +70,7 @@ class EnterPasscodeStateTests: XCTestCase { var called = false - override func passcodeLockDidFail(lock: PasscodeLockType) { + override func passcodeLockDidFail(_ lock: PasscodeLockType) { called = true } @@ -88,7 +88,7 @@ class EnterPasscodeStateTests: XCTestCase { let observer = NotificaionObserver() - observer.observe(PasscodeLockIncorrectPasscodeNotification) + observer.observe(notification: PasscodeLockIncorrectPasscodeNotification) passcodeState.acceptPasscode(["0"], fromLock: passcodeLock) passcodeState.acceptPasscode(["0"], fromLock: passcodeLock) @@ -101,7 +101,7 @@ class EnterPasscodeStateTests: XCTestCase { let observer = NotificaionObserver() - observer.observe(PasscodeLockIncorrectPasscodeNotification) + observer.observe(notification: PasscodeLockIncorrectPasscodeNotification) passcodeState.acceptPasscode(["0"], fromLock: passcodeLock) passcodeState.acceptPasscode(["0"], fromLock: passcodeLock) diff --git a/PasscodeLockTests/PasscodeLock/PasscodeLockTests.swift b/PasscodeLockTests/PasscodeLock/PasscodeLockTests.swift old mode 100644 new mode 100755 index efb192a3..0ec9f6b9 --- a/PasscodeLockTests/PasscodeLock/PasscodeLockTests.swift +++ b/PasscodeLockTests/PasscodeLock/PasscodeLockTests.swift @@ -29,7 +29,7 @@ class PasscodeLockTests: XCTestCase { var called = false - override func passcodeLockDidChangeState(lock: PasscodeLockType) { + override func passcodeLockDidChangeState(_ lock: PasscodeLockType) { called = true } @@ -51,7 +51,7 @@ class PasscodeLockTests: XCTestCase { var called = false var signIndex = 0 - override func passcodeLock(lock: PasscodeLockType, addedSignAtIndex index: Int) { + override func passcodeLock(_ lock: PasscodeLockType, addedSignAtIndex index: Int) { called = true signIndex = index @@ -78,7 +78,7 @@ class PasscodeLockTests: XCTestCase { var called = false var signIndex = 0 - override func passcodeLock(lock: PasscodeLockType, removedSignAtIndex index: Int) { + override func passcodeLock(_ lock: PasscodeLockType, removedSignAtIndex index: Int) { called = true signIndex = index diff --git a/PasscodeLockTests/PasscodeLock/SetPasscodeStateTests.swift b/PasscodeLockTests/PasscodeLock/SetPasscodeStateTests.swift old mode 100644 new mode 100755 index 20ef1214..e90429a0 --- a/PasscodeLockTests/PasscodeLock/SetPasscodeStateTests.swift +++ b/PasscodeLockTests/PasscodeLock/SetPasscodeStateTests.swift @@ -31,7 +31,7 @@ class SetPasscodeStateTests: XCTestCase { var didChangedState = false - override func passcodeLockDidChangeState(lock: PasscodeLockType) { + override func passcodeLockDidChangeState(_ lock: PasscodeLockType) { didChangedState = true } diff --git a/PasscodeLockTests/PasscodeLockTests-Bridging-Header.h b/PasscodeLockTests/PasscodeLockTests-Bridging-Header.h old mode 100644 new mode 100755 From dc28824baa65639aff75750b93c3af117c218b84 Mon Sep 17 00:00:00 2001 From: garanda21 Date: Tue, 23 Jul 2019 15:26:09 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 41ad441d..5c84327e 100755 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ A Swift implementation of passcode lock for iOS with TouchID authentication. +Originally created by [@yankodimitrov](https://github.com/yankodimitrov/SwiftPasscodeLock), and updated to swift 5 for me + ## Installation PasscodeLock requires Swift 2.0 and Xcode 7