Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Ejecutamos la búqueda
let status = SecItemCopyMatching(query as CFDictionary, &item)
// Comprobamos si no aparece el elemento...
if status == errSecItemNotFound
{
return Result.failure(KeychainError.passwordNotFound)
}
// ...y en caso de encontrarlos lo procesamos
if status == errSecSuccess
{
guard let existingItem = item as? [String : Any],
let passwordData = existingItem[kSecValueData as String] as? Data,
let password = String(data: passwordData, encoding: .utf8),
let account = existingItem[kSecAttrAccount as String] as? String
else
{
return Result.failure(KeychainError.malformedData)
}
let user = User(named: account, withPassword: password)
return Result.success(user)
}
else
{
return Result.failure(KeychainError.unknown(status: status))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.