title: Is it possible to update a Keychain item's kSecAttrAccessible value?
body: <p>Is it possible to update the value of the attribute <code>kSecAttrAccessible</code> of existing items in the Keychain? It seems that it cannot be changed after the item was added to the Keychain. The following steps back up my assumption.</p>
  
  <p>Add a new item to the Keychain:</p>
  
  <pre><code>NSData *encodedIdentifier = [@"BUNDLE_IDENTIFIER" 
                               dataUsingEncoding:NSUTF8StringEncoding];
  NSData *encodedPassword = [@"PASSWORD"
                             dataUsingEncoding:NSUTF8StringEncoding];
  
  // Construct a Keychain item
  NSDictionary *keychainItem = 
      [NSDictionary dictionaryWithObjectsAndKeys:
          kSecClassGenericPassword, kSecClass,
          encodedIdentifier, kSecAttrGeneric,
          encodedIdentifier, kSecAttrService,
          @"USERNAME", kSecAttrAccount,
          kSecAttrAccessibleWhenUnlocked, kSecAttrAccessible,
          encodedPassword, kSecValueData
          nil];
  
  // Add item to Keychain
  OSStatus addItemStatus = SecItemAdd((CFDictionaryRef)keychainItem, NULL);
  </code></pre>
  
  <p>At a later time, change the attribute <code>kSecAttrAccessible</code> from <code>kSecAttrAccessibleWhenUnlocked</code> to <code>kSecAttrAccessibleAfterFirstUnlock</code>:</p>
  
  <pre><code>NSData *encodedIdentifier = [@"BUNDLE_IDENTIFIER" 
                               dataUsingEncoding:NSUTF8StringEncoding];
  
  NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
                         kSecClassGenericPassword, kSecClass,
                         encodedIdentifier, kSecAttrGeneric,
                         encodedIdentifier, kSecAttrService,
                         nil];
  
  NSDictionary *updatedAttributes = 
      [NSDictionary dictionaryWithObject:kSecAttrAccessibleAfterFirstUnlock 
                                  forKey:kSecAttrAccessible];
  
  OSStatus updateItemStatus = SecItemUpdate((CFDictionaryRef)query, 
                                            (CFDictionaryRef)updatedAttributes);
  </code></pre>
  
  <p>The problem with this approach is that <code>updateItemStatus</code> always results in the status <code>errSecUnimplemented</code>. </p>
  
  <p>I think it should be possible to update the value of <code>kSecAttrAccessible</code> because requirements of applications change. What if an application added ten items to the Keychain in the past without specifying the protection class with <code>kSecAttrAccessible</code>. The Keychain implicitly assigns new items the value <code>kSecAttrAccessibleWhenUnlocked</code> if the protection class is not set explicitly by the developer. Later, the developer needs to change the protection class to <code>kSecAttrAccessibleAfterFirstUnlock</code> because the application must access it in the background (Multitasking). How can the developer accomplish that?</p>
  
  <p>There is already a thread in the Apple Developer Forums, but it has not yielded an answer yet: <a href="https://devforums.apple.com/thread/87646?tstart=0">https://devforums.apple.com/thread/87646?tstart=0</a></p>