user1141351 user1141351 - 4 months ago 13x
iOS Question

Cannot invoke initializer for type 'NSDictionary' in Swift2.0

It is probably simple but, since I'm not very experienced at Swift, I can't figure how to port this line to 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);

the error message:
Cannot invoke initializer for type 'NSDictionary' with an argument list of type '(objects: NSArray, forKeys: [CFString])'

let identifier = "someIdentifier"
let dataFromString = "someData"
let values = [kSecClassGenericPassword, identifier, dataFromString]
let keys: [NSString] = [kSecClass, kSecAttrService, kSecValueData]
let keychainQuery = NSDictionary(objects: values, forKeys: keys)