Skip to content

Instantly share code, notes, and snippets.

@norio-nomura
Created February 23, 2010 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save norio-nomura/311748 to your computer and use it in GitHub Desktop.
Save norio-nomura/311748 to your computer and use it in GitHub Desktop.
SecItemDelete sample
- (void)removeObjectForKey:(NSString*)key {
#if !TARGET_IPHONE_SIMULATOR
@synchronized(self) {
if (!deleteQueryDictionary) {
deleteQueryDictionary = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
(id)kSecClassGenericPassword, (id)kSecClass,
key, (id)kSecAttrAccount,
(id)kSecMatchLimitAll, (id)kSecMatchLimit,
(id)kCFBooleanTrue, (id)kSecReturnAttributes,
nil];
} else {
[deleteQueryDictionary setObject:key forKey:(id)kSecAttrAccount];
}
NSArray *itemList = nil;
OSStatus osStatus = SecItemCopyMatching((CFDictionaryRef)deleteQueryDictionary, (CFTypeRef *)&itemList);
if (osStatus == noErr) {
for (NSDictionary *item in itemList) {
NSMutableDictionary *query = [item mutableCopy];
[query setValue:(id)kSecClassGenericPassword forKey:(id)kSecClass];
osStatus = SecItemDelete((CFDictionaryRef)query);
if (osStatus != noErr) {
NSLog(@"osStatus:%d",osStatus);
}
[query release];
}
} else if (osStatus != errSecItemNotFound){
NSLog(@"osStatus:%d",osStatus);
}
[itemList release];
}
#else
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment