类型 'CFStringRef' 不符合 Xcode 6.1 中的协议 'Hashable' [英] Type 'CFStringRef' does not conform to protocol 'Hashable' in Xcode 6.1

查看:22
本文介绍了类型 'CFStringRef' 不符合 Xcode 6.1 中的协议 'Hashable'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个在 Xcode 6 中工作的 Keychain 访问类,但现在在 Xcode 6.1 中出现了一些错误,这是第一个错误:类型CFStringRef"不符合协议Hashable":

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

我也收到与第一个类似的错误,但它是:类型CFStringRef"不符合协议NSCopying"这里是我收到此错误的部分:

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.

推荐答案

CFStringRefNSString 桥接,String 桥接.最简单的解决方案是将 kSecValueDatakSecClass 强制转换为 Strings 或 NSStrings:

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

这里:

let updateDictionary = [kSecValueData as String: value]

这里:

var keychainQueryDictionary: NSMutableDictionary = [kSecClass as NSString: kSecClassGenericPassword]

这篇关于类型 'CFStringRef' 不符合 Xcode 6.1 中的协议 'Hashable'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆