I would like to save within an account [email protected] two values. Example of the dictionaries:
- Value 1.
kSecAttrAccount = [email protected]
kSecAttrGeneric = value1Key
kSecValueData = value1
- Value 2.
kSecAttrAccount = [email protected]
kSecAttrGeneric = value2Key
kSecValueData = value2
Is it possible? I'm getting an error to do the query when I try to keep the second value.
I attach a snippet of my code:
func addCredentials(_ credentials: KeychainCredentials) throws {
let account = credentials.account
let password = credentials.password.data(using: String.Encoding.utf8)!
let generic = credentials.generic
let accessControl = SecAccessControlCreateWithFlags(kCFAllocatorDefault,
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
.userPresence,
nil)
// Build the query
let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: serviceName,
kSecAttrAccount as String: account,
kSecAttrGeneric as String: generic,
kSecAttrAccessControl as String: accessControl as Any,
kSecValueData as String: password]
let status = SecItemAdd(query as CFDictionary, nil)
guard status == errSecSuccess else { throw KeychainError(status: status) }
}