类型';CFStringRef';不符合协议';可散列';在Xcode 6.1中
在我的应用程序中,我有一个密钥链访问类,该类在Xcode 6中工作,但现在在Xcode 6.1中我遇到一些错误这是第一个错误:“CFStringRef”类型不符合协议“Hashable”:类型';CFStringRef';不符合协议';可散列';在Xcode 6.1中,xcode,swift,Xcode,Swift,在我的应用程序中,我有一个密钥链访问类,该类在Xcode 6中工作,但现在在Xcode 6.1中我遇到一些错误这是第一个错误:“CFStringRef”类型不符合协议“Hashable”: private class func updateData(value: NSData, forKey keyName: String) -> Bool { let keychainQueryDictionary: NSMutableDictionary = self.setupKeychain
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
}
}
我也得到了一个类似于第一个错误的错误,但它是:类型'CFStringRef'不符合协议'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
s或NSString
s:
在这里:
在这里:
var keychainQueryDictionary: NSMutableDictionary = [kSecClass as NSString: kSecClassGenericPassword]
我认为它会更具可读性
let keychainQueryDictionary : [String: AnyObject] = [
kSecClass : kSecClassGenericPassword,
kSecAttrService : serviceIdentifier,
kSecAttrAccount : accountName
]
let keychainQueryDictionary : [String: AnyObject] = [
kSecClass : kSecClassGenericPassword,
kSecAttrService : serviceIdentifier,
kSecAttrAccount : accountName
]