0

I'm using the Keychain like so:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
[keychain setObject:responseObject[@"TOK"] forKey:CFBridgingRelease(kSecAttrAccount)];

And wish to remove (null the value) like so:

[keychain setValue:nil forKey:CFBridgingRelease(kSecAttrAccount)];

However, i only see this:

setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key acct.

Like wise, when i use this:

[keychain setNilValueForKey:CFBridgingRelease(kSecAttrAccount)];

I get this:

setNilValueForKey]: could not set nil as the value for the key acct.

I'm using apple's KeychainItemWrapper, How would i do this correctly?

Simon.
  • 1,886
  • 5
  • 29
  • 62
  • usually you need to delete the item, you cannot update it with a `nil` value directly, the `SecItemDelete(...)` method will do the job for you without any crash. – holex Dec 01 '14 at 16:17

1 Answers1

2

In general to delete an item, generate the query you will normally do to fetch it, then use "SecItemDelete".

Like this -

    NSMutableDictionary *query = [self getQueryForKey:key];
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)query);
if( status != errSecSuccess) {
    ...
}

If you're using the keyChainWrapper you can do -

    KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
    [keychain resetKeychainItem];
Yoshkebab
  • 770
  • 1
  • 7
  • 14