Skip to content

Instantly share code, notes, and snippets.

@brkphp
Last active November 15, 2018 08:45
Show Gist options
  • Save brkphp/7973f0db72f9907e287ea93f68e8388d to your computer and use it in GitHub Desktop.
Save brkphp/7973f0db72f9907e287ea93f68e8388d to your computer and use it in GitHub Desktop.
PasscodeRepository
import UIKit
import Foundation
import PasscodeLock
class PasscodeRepository: PasscodeRepositoryType {
private let passcodeKey = "passcode.lock.passcode"
var hasPasscode: Bool {
if passcode != nil {
return true
}
return false
}
var passcode: [String]? {
var code: [String] = []
if (keychain.standard.string(forKey:passcodeKey + String(1)) ?? nil) != nil{
for index in 0...3 {
code.append(keychain.standard.string(forKey:passcodeKey + String(index))!)
}
}
if code.count > 0 {
return code
}else{
return nil
}
}
func savePasscode(_ passcode: [String]) {
for (index, code) in passcode.enumerated() {
keychain.standard.set(code, forKey:passcodeKey + String(index))
}
}
func deletePasscode() {
for index in 0...3 {
keychain.standard.removeObject(forKey:passcodeKey + String(index))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment