unifiedContacts(matching:keysToFetch:)
Fetches all unified contacts matching the specified predicate.
Declaration
func unifiedContacts(matching predicate: NSPredicate, keysToFetch keys: [any CNKeyDescriptor]) throws -> [CNContact]Parameters
- predicate:
The predicate to match against.
- keys:
The properties to fetch in the returned Cncontact objects. Fetch only the properties that your app uses. You can combine contact keys and contact key descriptors.
Return Value
An array of CNContact objects matching the predicate.
Discussion
If the system doesn’t find any matches, this method returns an empty array (or nil in case of error). Use only the predicates from the CNContact class predicates. This method doesn’t support compound predicates. Due to unification, the returned contacts may have different identifiers than you specify. To fetch all contacts, use enumerateContacts(with:usingBlock:).
To include CNContactNoteKey in the array of keys in iOS, add the com.apple.developer.contacts.notes entitlement to your app. The entitlement requires permission from Apple to use, and you can’t publicly distribute your app until you have permission to use it. For more information about adding the entitlement and getting permission, see com.apple.developer.contacts.notes.