Type "CFStringRef" does not conform to the "Hashable" protocol in Xcode 6.1

In my application, I have a Keychain access class that worked in Xcode 6, but now in Xcode 6.1 I get some errors, this is the first: Type 'CFStringRef' does not conform to the "Hashable" protocol:

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 } } 

I also get an error similar to the first, but this: Type 'CFStringRef' does not comply with the 'NSCopying' protocol, here is the part where I get this error:

 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 } 

Can someone tell me how to solve this error, please.

+5
source share
2 answers

CFStringRef connects to NSString , which connects to String . The simplest solution is to simply drop kSecValueData and kSecClass into String or NSString s:

Here:

 let updateDictionary = [kSecValueData as String: value] 

And here:

 var keychainQueryDictionary: NSMutableDictionary = [kSecClass as NSString: kSecClassGenericPassword] 
+8
source

I think it will be more readable

 let keychainQueryDictionary : [String: AnyObject] = [ kSecClass : kSecClassGenericPassword, kSecAttrService : serviceIdentifier, kSecAttrAccount : accountName ] 
+4
source

Source: https://habr.com/ru/post/1205527/


All Articles