SecItemDelete(_:)
Deletes items that match a search query.
Declaration
func SecItemDelete(_ query: CFDictionary) -> OSStatusParameters
- query:
A dictionary that describes the search for the keychain items you want to delete. A typical
querydictionary consists of:The item’s class. Specify the kind of item you want, for example a password, a certificate, or a cryptographic key, using one of the class values in Item Class Keys And Values.
Attributes. Narrow the search by indicating the attributes that the found item or items should have. The more attributes you specify, the more refined the results, but not all attributes apply to all item classes. For the attributes applicable to the keychain item you’re deleting, see the entry for the item’s class in Item Class Keys And Values.
Search parameters. Condition the search in a variety of ways. For example, you can limit the results to a specific number of items, control case sensitivity when matching string attributes, or search only among a particular set of items. See Search Attribute Keys And Values for the complete list of possible search parameters.
Mentioned in
Return Value
A result code. See Security Framework Result Codes.
Discussion
The query dictionary for delete can’t contain Item return result keys, because SecItemDelete(_:) only returns a status.
By default, this function deletes all items matching the specified query. You can change this behavior by specifying a key, as follows:
To delete an item identified by a transient reference, specify the kSecMatchItemList search key with a reference returned by using the kSecReturnRef return type key in a previous call to the SecItemCopyMatching(_:_:) or SecItemAdd(_:_:) functions.
To delete an item identified by a persistent reference, specify the kSecMatchItemList search key with a persistent reference returned by using the kSecReturnPersistentRef return type key to the SecItemCopyMatching(_:_:) or SecItemAdd(_:_:) functions.
If more than one of these return keys is specified, the behavior is undefined.
Performance considerations
SecItemDelete blocks the calling thread, so it can cause your app’s UI to hang if called from the main thread. Instead, call SecItemDelete from a background dispatch queue or async function: