类型’CFStringRef’不符合Xcode 6.1中的协议’Hashable’
发布时间:2020-12-14 19:25:50 所属栏目:百科 来源:网络整理
导读:在我的应用程序中,我有一个在 Xcode 6中工作的Keychain访问类,但现在在Xcode 6.1中我得到一些错误,这是第一个:Type’CFStringRef’不符合协议’Hashable’: private class func updateData(value: NSData,forKey keyName: String) - Bool { let keychainQu
在我的应用程序中,我有一个在
Xcode 6中工作的Keychain访问类,但现在在Xcode 6.1中我得到一些错误,这是第一个:Type’CFStringRef’不符合协议’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’这里是我得到此错误的部分: 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桥接,NSString与String桥接.最简单的解决方案是将kSecValueData和kSecClass转换为字符串或NSStrings:
这里: let updateDictionary = [kSecValueData as String: value] 和这里: var keychainQueryDictionary: NSMutableDictionary = [kSecClass as NSString: kSecClassGenericPassword] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |