Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类型';CFStringRef';不符合协议';可散列';在Xcode 6.1中_Xcode_Swift - Fatal编程技术网

类型';CFStringRef';不符合协议';可散列';在Xcode 6.1中

类型';CFStringRef';不符合协议';可散列';在Xcode 6.1中,xcode,swift,Xcode,Swift,在我的应用程序中,我有一个密钥链访问类,该类在Xcode 6中工作,但现在在Xcode 6.1中我遇到一些错误这是第一个错误:“CFStringRef”类型不符合协议“Hashable”: private class func updateData(value: NSData, forKey keyName: String) -> Bool { let keychainQueryDictionary: NSMutableDictionary = self.setupKeychain

在我的应用程序中,我有一个密钥链访问类,该类在Xcode 6中工作,但现在在Xcode 6.1中我遇到一些错误这是第一个错误:“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
桥接,后者与
String
桥接。最简单的解决方案是将
kSecValueData
kSecClass
转换为
String
s或
NSString
s:

在这里:

在这里:

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

我认为它会更具可读性

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