Query keychain for "Not Equal" results

let query: [String : Any] = 
                  [kSecClass as String : kSecClassGenericPassword,
                   kSecAttrLabel as String : "hello@email.com"]

let status = SecItemDelete(query as CFDictionary)

A query like above helps to search the keychain and delete the entries that have AttrLabel as "hello@email.com" .

However we are having a requirement to delete the entires that don't match "hello@email.com", basically we want to get all entries that are NOT EQUAL TO "hello@email.com".

I checked on the documentation and other links, we could not find on details whether it is possible to pass != condition to keychain query

Please suggest

Regards, Vinoth

Replies

The SecItem API does not negative query terms. To achieve this goal you’ll have to fetch all the items, filter the list based on your criteria, and then delete the ones you don’t want.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"