You want to delete a keychain item.
In Recipe 8.2, we learned
how to store values in the keychain. In order to delete those values,
you will need to use the
SecItemDelete function. This function takes
only one parameter: a dictionary of type
CFDictionaryRef. You can take a normal
dictionary and bridge-convert it to an instance of
CFDictionaryRef, as we have done in other
recipes in this chapter. The dictionary that you’ll pass to this method
has to contain the following keys:
The type of item that you want to delete. For instance
The service that this item is hooked to. When you stored the item, you chose the service for it, so you’ll need to provide the same service here. For instance, in previous examples, we set the value of this key to our app’s bundle identifier. If that’s what you did as well, simply provide your app’s bundle identifier for the value of this key.
The value of this key is the key that has to be deleted.
Assuming you have followed Recipe 8.2, the keychain now has a
generic password (
kSecClassGenericPassword) with the service
kSecAttrService) equal to our
app’s bundle ID and the key (
kSecAttrAccount) equal to
Name. To delete this key, here is what you’ll have to