title: Does the Keychain in iOS actually work?
body: <p>I've been trying to use the keychain in iOS for storing some small bits of information — password strings, OAuth tokens, etc. I'm using the KeychainItemWrapper sample code that Apple provides here: 
  <a href="https://developer.apple.com/library/ios/#samplecode/GenericKeychain/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007797" rel="noreferrer">https://developer.apple.com/library/ios/#samplecode/GenericKeychain/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007797</a></p>
  
  <p>I've found it extremely buggy! Sometimes it works, other times my app crashes when trying to store string values in the keychain, particularly when something was already set. Other times, the exact same calls work just fine. The errors happen on actual devices, not in the simulator.</p>
  
  <p>The way I typically write to the keychain is like this:</p>
  
  <pre><code>KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"password" accessGroup:nil];
  [wrapper setObject:thePasswordString forKey:(id)kSecValueData];
  [wrapper release];
  </code></pre>
  
  <p>So, what I would like to know is: am I doing something wrong, is the sample code from Apple to blame, or is the actual underlying iOS keychain API broken?</p>