Skip to content
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
97 changes: 55 additions & 42 deletions PasscodeLock.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions PasscodeLock/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import Foundation
func localizedStringFor(key: String, comment: String) -> String {

let name = "PasscodeLock"
let bundle = bundleForResource(name, ofType: "strings")
let bundle = bundleForResource(name: name, ofType: "strings")

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)
}
8 changes: 4 additions & 4 deletions PasscodeLock/PasscodeLock/ChangePasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct ChangePasscodeState: PasscodeLockStateType {

init() {

title = localizedStringFor("PasscodeLockChangeTitle", comment: "Change passcode title")
description = localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description")
title = localizedStringFor(key: "PasscodeLockChangeTitle", comment: "Change passcode title")
description = localizedStringFor(key: "PasscodeLockChangeDescription", comment: "Change passcode description")
}

func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) {
Expand All @@ -31,11 +31,11 @@ struct ChangePasscodeState: PasscodeLockStateType {

let nextState = SetPasscodeState()

lock.changeStateTo(nextState)
lock.changeStateTo(state: nextState)

} else {

lock.delegate?.passcodeLockDidFail(lock)
lock.delegate?.passcodeLockDidFail(lock: lock)
}
}
}
16 changes: 8 additions & 8 deletions PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ struct ConfirmPasscodeState: PasscodeLockStateType {
init(passcode: [String]) {

passcodeToConfirm = passcode
title = localizedStringFor("PasscodeLockConfirmTitle", comment: "Confirm passcode title")
description = localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description")
title = localizedStringFor(key: "PasscodeLockConfirmTitle", comment: "Confirm passcode title")
description = localizedStringFor(key: "PasscodeLockConfirmDescription", comment: "Confirm passcode description")
}

func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) {

if passcode == passcodeToConfirm {

lock.repository.savePasscode(passcode)
lock.delegate?.passcodeLockDidSucceed(lock)
lock.repository.savePasscode(passcode: passcode)
lock.delegate?.passcodeLockDidSucceed(lock: lock)

} else {

let mismatchTitle = localizedStringFor("PasscodeLockMismatchTitle", comment: "Passcode mismatch title")
let mismatchDescription = localizedStringFor("PasscodeLockMismatchDescription", comment: "Passcode mismatch description")
let mismatchTitle = localizedStringFor(key: "PasscodeLockMismatchTitle", comment: "Passcode mismatch title")
let mismatchDescription = localizedStringFor(key: "PasscodeLockMismatchDescription", comment: "Passcode mismatch description")

let nextState = SetPasscodeState(title: mismatchTitle, description: mismatchDescription)

lock.changeStateTo(nextState)
lock.delegate?.passcodeLockDidFail(lock)
lock.changeStateTo(state: nextState)
lock.delegate?.passcodeLockDidFail(lock: lock)
}
}
}
12 changes: 6 additions & 6 deletions PasscodeLock/PasscodeLock/EnterPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct EnterPasscodeState: PasscodeLockStateType {
init(allowCancellation: Bool = false) {

isCancellableAction = allowCancellation
title = localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title")
description = localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description")
title = localizedStringFor(key: "PasscodeLockEnterTitle", comment: "Enter passcode title")
description = localizedStringFor(key: "PasscodeLockEnterDescription", comment: "Enter passcode description")
}

mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) {
Expand All @@ -35,7 +35,7 @@ struct EnterPasscodeState: PasscodeLockStateType {

if passcode == currentPasscode {

lock.delegate?.passcodeLockDidSucceed(lock)
lock.delegate?.passcodeLockDidSucceed(lock: lock)

} else {

Expand All @@ -46,17 +46,17 @@ struct EnterPasscodeState: PasscodeLockStateType {
postNotification()
}

lock.delegate?.passcodeLockDidFail(lock)
lock.delegate?.passcodeLockDidFail(lock: lock)
}
}

private mutating func postNotification() {

guard !isNotificationSent else { return }

let center = NSNotificationCenter.defaultCenter()
let center = NotificationCenter.default

center.postNotificationName(PasscodeLockIncorrectPasscodeNotification, object: nil)
center.post(name: NSNotification.Name(rawValue: PasscodeLockIncorrectPasscodeNotification), object: nil)

isNotificationSent = true
}
Expand Down
29 changes: 15 additions & 14 deletions PasscodeLock/PasscodeLock/PasscodeLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public class PasscodeLock: PasscodeLockType {
public func addSign(sign: String) {

passcode.append(sign)
delegate?.passcodeLock(self, addedSignAtIndex: passcode.count - 1)
delegate?.passcodeLock(lock: self, addedSignAtIndex: passcode.count - 1)

if passcode.count >= configuration.passcodeLength {

lockState.acceptPasscode(passcode, fromLock: self)
passcode.removeAll(keepCapacity: true)
lockState.acceptPasscode(passcode: passcode, fromLock: self)
passcode.removeAll(keepingCapacity: true)
}
}

Expand All @@ -54,38 +54,39 @@ public class PasscodeLock: PasscodeLockType {
guard passcode.count > 0 else { return }

passcode.removeLast()
delegate?.passcodeLock(self, removedSignAtIndex: passcode.count)
delegate?.passcodeLock(lock: self, removedSignAtIndex: passcode.count)
}

public func changeStateTo(state: PasscodeLockStateType) {

lockState = state
delegate?.passcodeLockDidChangeState(self)
DispatchQueue.main.async {
self.lockState = state
self.delegate?.passcodeLockDidChangeState(lock: self)
}
}

public func authenticateWithBiometrics() {

guard isTouchIDAllowed else { return }

let context = LAContext()
let reason = localizedStringFor("PasscodeLockTouchIDReason", comment: "TouchID authentication reason")
let reason = localizedStringFor(key: "PasscodeLockTouchIDReason", comment: "TouchID authentication reason")

context.localizedFallbackTitle = localizedStringFor("PasscodeLockTouchIDButton", comment: "TouchID authentication fallback button")
context.localizedFallbackTitle = localizedStringFor(key: "PasscodeLockTouchIDButton", comment: "TouchID authentication fallback button")

context.evaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
success, error in

self.handleTouchIDResult(success)
self.handleTouchIDResult(success: success)
}
}

private func handleTouchIDResult(success: Bool) {

dispatch_async(dispatch_get_main_queue()) {
DispatchQueue.main.async() {

if success {

self.delegate?.passcodeLockDidSucceed(self)
self.delegate?.passcodeLockDidSucceed(lock: self)
}
}
}
Expand All @@ -94,6 +95,6 @@ public class PasscodeLock: PasscodeLockType {

let context = LAContext()

return context.canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil)
return context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
}
}
6 changes: 3 additions & 3 deletions PasscodeLock/PasscodeLock/SetPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ struct SetPasscodeState: PasscodeLockStateType {

init() {

title = localizedStringFor("PasscodeLockSetTitle", comment: "Set passcode title")
description = localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description")
title = localizedStringFor(key: "PasscodeLockSetTitle", comment: "Set passcode title")
description = localizedStringFor(key: "PasscodeLockSetDescription", comment: "Set passcode description")
}

func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType) {

let nextState = ConfirmPasscodeState(passcode: passcode)

lock.changeStateTo(nextState)
lock.changeStateTo(state: nextState)
}
}
26 changes: 13 additions & 13 deletions PasscodeLock/PasscodeLockPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class PasscodeLockPresenter {

private 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
Expand All @@ -29,7 +29,7 @@ public class PasscodeLockPresenter {
public init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, viewController: PasscodeLockViewController) {

mainWindow = window
mainWindow?.windowLevel = 1
mainWindow?.windowLevel = UIWindow.Level(rawValue: 1)
passcodeConfiguration = configuration

passcodeLockVC = viewController
Expand All @@ -49,10 +49,10 @@ public class PasscodeLockPresenter {

isPasscodePresented = true

passcodeLockWindow.windowLevel = 2
passcodeLockWindow.hidden = false
passcodeLockWindow.windowLevel = UIWindow.Level(rawValue: 2)
passcodeLockWindow.isHidden = false

mainWindow?.windowLevel = 1
mainWindow?.windowLevel = UIWindow.Level(rawValue: 1)
mainWindow?.endEditing(true)

let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: passcodeConfiguration)
Expand All @@ -68,10 +68,10 @@ public class PasscodeLockPresenter {
passcodeLockWindow.rootViewController = passcodeLockVC
}

public func dismissPasscodeLock(animated animated: Bool = true) {
public func dismissPasscodeLock(animated: Bool = true) {

isPasscodePresented = false
mainWindow?.windowLevel = 1
mainWindow?.windowLevel = UIWindow.Level(rawValue: 1)
mainWindow?.makeKeyAndVisible()

if animated {
Expand All @@ -80,26 +80,26 @@ public class PasscodeLockPresenter {

} else {

passcodeLockWindow.windowLevel = 0
passcodeLockWindow.windowLevel = UIWindow.Level(rawValue: 0)
passcodeLockWindow.rootViewController = nil
}
}

internal func animatePasscodeLockDismissal() {

UIView.animateWithDuration(
0.5,
UIView.animate(
withDuration: 0.5,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: [.CurveEaseInOut],
options: [.curveEaseOut],
animations: { [weak self] in

self?.passcodeLockWindow.alpha = 0
},
completion: { [weak self] _ in

self?.passcodeLockWindow.windowLevel = 0
self?.passcodeLockWindow.windowLevel = UIWindow.Level(rawValue: 0)
self?.passcodeLockWindow.rootViewController = nil
self?.passcodeLockWindow.alpha = 1
}
Expand Down
Loading