Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created September 20, 2018 09:15
Show Gist options
  • Select an option

  • Save Arrlindii/6fff4ba3d609123e4c153cc83c18749d to your computer and use it in GitHub Desktop.

Select an option

Save Arrlindii/6fff4ba3d609123e4c153cc83c18749d to your computer and use it in GitHub Desktop.
class KeychainService {
func save(_ password: String, for account: String) {
let password = password.data(using: String.Encoding.utf8)!
let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: account,
kSecValueData as String: password]
let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else { return print("save error")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment