title: Keychain service for iOS, delete keychain error
body: <p>I've wrote a project using <a href="http://developer.apple.com/library/mac/#documentation/Security/Conceptual/keychainServConcepts/iPhoneTasks/iPhoneTasks.html#//apple_ref/doc/uid/TP30000897-CH208-SW1" rel="nofollow">iOS keychain wrapper</a> to store user name and password,<br>and the project works fine until Yesterday.<br> 
  After I ran clean command to the project, the project crash in:</p>
  
  <pre><code>- (void)writeToKeychain
  {
      NSDictionary *attributes = NULL;
      NSMutableDictionary *updateItem = NULL;
  
      // If the keychain item already exists, modify it:  
      if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery,
                              (CFTypeRef *)&amp;attributes) == noErr)
      {
          // First, get the attributes returned from the keychain and add them to the
          // dictionary that controls the update:
          updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes];
  
      // Second, get the class value from the generic password query dictionary and
      // add it to the updateItem dictionary:
      [updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass]
                     forKey:(id)kSecClass];
  
      // Finally, set up the dictionary that contains new values for the attributes:
      NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainData];
  
      //Remove the class--it's not a keychain attribute:
      [tempCheck removeObjectForKey:(id)kSecClass];
  
      // You can update only a single keychain item at a time.
      NSAssert(SecItemUpdate((CFDictionaryRef)updateItem,
                             (CFDictionaryRef)tempCheck) == noErr,
               @"Couldn't update the Keychain Item." );
  }
  else    
  {
      // No previous item found; add the new item.
      // The new value was added to the keychainData dictionary in the mySetObject routine,
      //  and the other values were added to the keychainData dictionary previously.
  
      // No pointer to the newly-added items is needed, so pass NULL for the second parameter:
      //NSAssert(SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainData],
      //                  NULL) == noErr, @"Couldn't add the Keychain Item." );       
      NSLog(@"%ld", SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainData],NULL));
      NSLog(@"%ld", SecItemDelete((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainData]));
  }
  
  }
  </code></pre>
  
  <p>In order to debug, I comment the NSAssert and add 3 NSLog.<br>
  However, I got error:</p>
  
  <blockquote>
    <p>-25299(errSecDuplicateItem, The item already exists.) </p>
  </blockquote>
  
  <p>of SecItemAdd and </p>
  
  <blockquote>
    <p>-25300(errSecItemNotFound, The item cannot be found.) </p>
  </blockquote>
  
  <p>of SecItemDelete</p>
  
  <p>How do I remove the old keychain item in my device?</p>