// Function to check if a user account already exists in Keychain
static func doesAnyUserExist() -> Bool {
// Define query parameters
let query: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecMatchLimit as String: kSecMatchLimitOne,
kSecReturnAttributes as String: true
]
// Try to fetch existing item from Keychain
var result: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &result)
print("doesAnyUserExist SecItemCopyMatching status: \(status)")
// Check if user account exists or not
if status == errSecSuccess {
return true
} else if status == errSecItemNotFound {
return false
} else {
print("Keychain error: \(status)")
return false
}
}