Skip to content

Instantly share code, notes, and snippets.

@mohammad19991
Created June 20, 2018 12:30
Show Gist options
  • Save mohammad19991/584a199065173c72ca82afc998381e06 to your computer and use it in GitHub Desktop.
Save mohammad19991/584a199065173c72ca82afc998381e06 to your computer and use it in GitHub Desktop.
//1
let keychain = Keychain(server: domain, protocolType: .https).synchronizable(true)
let email = UserDefaults.standard.object(forKey: "account") as? String
//2
if let account = email, let password = try? keychain.get(account) {
return password
}else {
//3
keychain.getSharedPassword({ [weak self] (account, password, error) in
guard let account = account, let password = password else { return }
//4
keychain[account] = password
return password
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment