这可能很简单但是,由于我在Swift上不是很有经验,所以我无法想象如何将这一行移植到Swift 2.0。
func setPasscode(identifier: String, passcode: String) {
var dataFromString: NSData = passcode.dataUsingEncoding(NSUTF8StringEncoding)!;
var keychainQuery = NSDictionary(objects: [kSecClassGenericPassword, identifier, dataFromString], forKeys: [kSecClass, kSecAttrService, kSecValueData])
SecItemDelete(keychainQuery as CFDictionaryRef);
var status: OSStatus = SecItemAdd(keychainQuery as CFDictionaryRef, nil);
}
错误消息: 无法为类型' NSDictionary'调用初始化程序。使用类型'的参数列表(对象:NSArray,forKeys:[CFString])'
答案 0 :(得分:1)
let identifier = "someIdentifier"
let dataFromString = "someData"
let values = [kSecClassGenericPassword, identifier, dataFromString]
let keys: [NSString] = [kSecClass, kSecAttrService, kSecValueData]
let keychainQuery = NSDictionary(objects: values, forKeys: keys)