Keychain fails on iOS 10 simulator

Number:rdar://27844971 Date Originated:15-Aug-2016 01:22 PM
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:Always
Accessing the Keychain from the iOS 10 simulator using Xcode 8 beta 2–5 fails with error code -34018 unless Keychain Sharing is enabled.

Steps to Reproduce:
1. Create a new Single page iOS app project in Xcode 8 beta 3.
2. Run the following code in viewDidLoad (or open the attached Xcode project).

    let itemKey = "My key"
    let itemValue = "My secretive bee 🐝"
    // Remove from Keychain
    // ----------------
    let queryDelete: [String: AnyObject] = [
      kSecClass as String: kSecClassGenericPassword,
      kSecAttrAccount as String: itemKey
    let resultCodeDelete = SecItemDelete(queryDelete as CFDictionary)
    if resultCodeDelete != noErr {
      print("Error deleting from Keychain: \(resultCodeDelete)")
    // Add to keychain
    // ----------------
    guard let valueData = String.Encoding.utf8) else {
      print("🐣🐣🐣🐣🐣🐣🐣🐣🐣🐣 Error saving text to Keychain")
    let queryAdd: [String: AnyObject] = [
      kSecClass as String: kSecClassGenericPassword,
      kSecAttrAccount as String: itemKey,
      kSecValueData as String: valueData,
      kSecAttrAccessible as String: kSecAttrAccessibleWhenUnlocked
    let resultCode = SecItemAdd(queryAdd as CFDictionary, nil)
    if resultCode != noErr {
      print("🐝🐝🐝🐝🐝🐝🐝🐝🐝 Error saving to Keychain: \(resultCode).")
    } else {
      print("πŸ€πŸ€πŸ€πŸ€πŸ€πŸ€πŸ€πŸ€πŸ€ Saved to keychain successfully.")

Expected Results:
Item is added to Keychain

Actual Results:
Function SecItemAdd returns the following error code: -34018

Xcode version 8.0 beta 5 (8S193k)
OS X version 10.11.5 (15F34)

Workaround: enable Keychain Sharing in the target settings’ Capabilities tab. Then Keychain works as expected.

This is a duplicate of rdar://27422249 although I added more detail here.


Always occurs in Xcode 8 beta 2–5 when testing in iOS 10 simulator (14A5309d).

Does NOT occur in Xcode 8 beta 2 and beta 3 when testing in iOS 9.3 simulator.

Does NOT occur in Xcode 8 beta 1 when testing in iOS 10 simulator (14A5261u).

'' was successfully uploaded.


Any Entitlement Works

I found any Entitlement works, it's not specific to the Keychain Sharing entitlement.

By patrick.mccarron at Sept. 20, 2016, 8:52 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!