<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecItemDelete(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecItemDelete"
  },
  "title" : "SecItemDelete(_:)"
}
-->

# SecItemDelete(_:)

Deletes items that match a search query.

```
func SecItemDelete(_ query: CFDictionary) -> OSStatus
```

## Parameters

`query`

A dictionary that describes the search for the keychain items you want to delete. A typical `query` dictionary 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](/documentation/Security/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 values](/documentation/Security/item-class-keys-and-values#Item-class-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](/documentation/Security/search-attribute-keys-and-values) for the complete list of possible search parameters.

## Return Value

A result code. See [Security Framework Result Codes](/documentation/Security/security-framework-result-codes).

## Discussion

The query dictionary for delete can’t contain [Item return result keys](/documentation/Security/item-return-result-keys), because [`SecItemDelete(_:)`](/documentation/Security/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`](/documentation/Security/kSecMatchItemList) search key with a reference returned by using the [`kSecReturnRef`](/documentation/Security/kSecReturnRef) return type key in a previous call to the [`SecItemCopyMatching(_:_:)`](/documentation/Security/SecItemCopyMatching(_:_:)) or [`SecItemAdd(_:_:)`](/documentation/Security/SecItemAdd(_:_:)) functions.
- To delete an item identified by a persistent reference, specify the [`kSecMatchItemList`](/documentation/Security/kSecMatchItemList) search key with a persistent reference returned by using the [`kSecReturnPersistentRef`](/documentation/Security/kSecReturnPersistentRef) return type key to the [`SecItemCopyMatching(_:_:)`](/documentation/Security/SecItemCopyMatching(_:_:)) or [`SecItemAdd(_:_:)`](/documentation/Security/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:

```swift
private func deleteKeychainItem(searchAttributes attrs: CFDictionary, _ completion: @escaping (OSStatus) -> Void) {
    queue.async {
        let result = SecItemDelete(attrs)
        completion(result)
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)