Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'CFStringRef' does not conform to protocol 'Hashable' in Xcode 6.1

Tags:

xcode

swift

In my app i have a Keychain access class that was working in Xcode 6 but now in Xcode 6.1 i get some errors this is the first one: the Type 'CFStringRef' does not conform to 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
    }
}

I also get a error similar to the the first one but it is: Type 'CFStringRef' does not conform to protocol 'NSCopying' 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 somebody tells me how to solve these error please.

like image 375
Clément Bisaillon Avatar asked Oct 26 '14 01:10

Clément Bisaillon


2 Answers

CFStringRef is bridged with NSString which is bridged with String. The simplest solution is to just cast kSecValueData and kSecClass to Strings or NSStrings:

Here:

let updateDictionary = [kSecValueData as String: value]

And here:

var keychainQueryDictionary: NSMutableDictionary = [kSecClass as NSString: kSecClassGenericPassword]
like image 134
Mike S Avatar answered Nov 15 '22 04:11

Mike S


I think it will be more readable

let keychainQueryDictionary : [String: AnyObject] = [
  kSecClass       : kSecClassGenericPassword,
  kSecAttrService : serviceIdentifier,
  kSecAttrAccount : accountName
]    
like image 28
dev4u Avatar answered Nov 15 '22 04:11

dev4u