Instance Method

enumerateContacts(with:usingBlock:)

Returns a Boolean value that indicates whether the enumeration of all contacts matching a contact fetch request executed successfully.

Declaration

func enumerateContacts(with fetchRequest: CNContactFetchRequest, usingBlock block: @escaping (CNContact, UnsafeMutablePointer<ObjCBool>) -> Void) throws

Parameters

fetchRequest

The contact fetch request that specifies the search criteria.

error

Error information, if an error occurred.

block

Called for each contact matching the fetch request.

Return Value

true if enumeration of all contacts matching a contact fetch request executes successfully; otherwise, false.

Discussion

This method waits until the enumeration is finished. If there are no results, the block is not called and the method returns true.

This method can fetch all contacts without keeping all of them at once in memory, which is expensive.

See Also

Fetching Contacts

func unifiedMeContactWithKeys(toFetch: [CNKeyDescriptor]) -> CNContact

Fetches the unified contact that is the "me" card.

func unifiedContact(withIdentifier: String, keysToFetch: [CNKeyDescriptor]) -> CNContact

Fetches a unified contact for the specified contact identifier.

func unifiedContacts(matching: NSPredicate, keysToFetch: [CNKeyDescriptor]) -> [CNContact]

Fetches all unified contacts matching the specified predicate.