Clement Bisaillon
Clement Bisaillon

Reputation: 5187

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

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.

Upvotes: 5

Views: 2286

Answers (2)

dev4u
dev4u

Reputation: 2113

I think it will be more readable

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

Upvotes: 4

Mike S
Mike S

Reputation: 42345

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]

Upvotes: 8

Related Questions