试图从钥匙串中检索所有项目

时间:2016-05-13 14:59:01

标签: swift

我试图遍历存储在钥匙串中的每件物品。我使用以下代码:

let query = [
    kSecReturnAttributes as String : kCFBooleanTrue as Bool,
    kSecMatchLimit as String : kSecMatchLimitAll as String,
]


let secItemClasses = [
    kSecClassGenericPassword,
    kSecClassInternetPassword,
    kSecClassCertificate,
    kSecClassKey,
    kSecClassIdentity
]


for secItemClass in secItemClasses {
    query.setValue(secItemClass as String, forKey: kSecClass as String)
    var result: AnyObject?
    SecItemCopyMatching(query, &result)
    print(result)
}

但是,我收到以下错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<__NSDictionaryI 0x7fce2b682b30> setValue:forUndefinedKey:]: this class is not key
 value coding-compliant for the key class.'

我该如何解决这个问题?

0 个答案:

没有答案