在我的应用程序中,我有一个在 Xcode 6 中工作的钥匙串(keychain)访问类,但现在在 Xcode 6.1 中我遇到了一些错误,这是第一个错误:类型 'CFStringRef' 不符合协议(protocol) 'Hashable':
private class func updateData(value: NSData, forKey keyName: String) -> Bool {
let keychainQueryDictionary: NSMutableDictionary = self.setupKeychainQueryDictionaryForKey(keyName)
let updateDictionary = [kSecValueData:value] //HERE IS THE ERROR
// Update
let status: OSStatus = SecItemUpdate(keychainQueryDictionary, updateDictionary)
if status == errSecSuccess {
return true
} else {
return false
}
}
我也收到与第一个错误类似的错误,但它是:Type 'CFStringRef' does not conform to protocol 'NSCopying' 这是我收到此错误的部分:
private class func setupKeychainQueryDictionaryForKey(keyName: String) -> NSMutableDictionary {
// Setup dictionary to access keychain and specify we are using a generic password (rather than a certificate, internet password, etc)
var keychainQueryDictionary: NSMutableDictionary = [kSecClass:kSecClassGenericPassword]
// HERE IS THE ERROR ↑↑↑
// Uniquely identify this keychain accessor
keychainQueryDictionary[kSecAttrService as String] = KeychainWrapper.serviceName
// Uniquely identify the account who will be accessing the keychain
var encodedIdentifier: NSData? = keyName.dataUsingEncoding(NSUTF8StringEncoding)
keychainQueryDictionary[kSecAttrGeneric as String] = encodedIdentifier
keychainQueryDictionary[kSecAttrAccount as String] = encodedIdentifier
return keychainQueryDictionary
}
有人能告诉我如何解决这些错误吗?
最佳答案
CFStringRef
与 NSString
桥接,后者与 String
桥接。最简单的解决方案是将 kSecValueData
和 kSecClass
转换为 String
或 NSString
:
这里:
let updateDictionary = [kSecValueData as String: value]
在这里:
var keychainQueryDictionary: NSMutableDictionary = [kSecClass as NSString: kSecClassGenericPassword]
关于xcode - 类型 'CFStringRef' 不符合 Xcode 6.1 中的协议(protocol) 'Hashable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26569000/