OS X 10.3.3, Xcode 7 beta 2. This simple function to add a key to a keychain in Swift is failing and I don't know why. Searching for the error hasn't been much help. The error is:
Swift.Unmanaged<ObjectiveC.CFString>(_value: The specified attribute does not exist.)
The number of attributes have been cut to what I think is the minimum. The code copied straight from a playground:
func addKeyToKeychain() -> NSData? {
let keyId = "org.snafu.testKey".dataUsingEncoding(NSUTF8StringEncoding,
allowLossyConversion: false)!
let keyData = NSMutableData(length: 64)!
let result = SecRandomCopyBytes(kSecRandomDefault, 64,
UnsafeMutablePointer<UInt8>(keyData.mutableBytes))
assert(result == 0)
let attributes: [NSString: AnyObject] = [
kSecClass: kSecClassKey,
kSecAttrApplicationTag: keyId,
kSecValueData: keyData,
kSecAttrKeySizeInBits: 512
]
let status = SecItemAdd(attributes as CFDictionary, nil)
if status != errSecSuccess {
print(SecCopyErrorMessageString(status, nil))
return nil
}
return keyData
}
Any ideas? Is this the proper place to be asking this question?