I'm not sure to what point this is relevant, but I'm also using Xcode 8, Beta 3 and I have a very simple keychain code like so:
| private func saveValueInKeychain(_ value: String, forKey key: String) { |
| var keychainDic = [NSObject : NSObject]() |
| let fixedKey = key + "_" + self.name |
| |
| keychainDic[kSecClass] = kSecClassGenericPassword |
| keychainDic[kSecAttrAccessible] = kSecAttrAccessibleWhenUnlocked |
| keychainDic[kSecAttrAccount] = fixedKey |
| |
| if(SecItemCopyMatching(keychainDic, nil) != noErr) { |
| / |
| keychainDic[kSecValueData] = value.data(using: .utf8) |
| let sts = SecItemAdd(keychainDic, nil) |
| print("Keychain status saving: \(sts)") |
| } |
| } |
This fails on my Unit Tests. If it matters, this is a Framework project.
Keychain status saving: -34018
But it works fine on an actual app when running it on the simulator:
Keychain status saving: 0
BUT, it did not work on my first try. It started returning 0 when I enabled shared keychain on my Entitlements. This small app does not need shared keychain entilements, but if I don't enable them, I get the error -34018.