Class

CNContactStore

The CNContactStore class is a thread-safe class that can fetch and save contacts, groups, and containers.

Overview

The CNContactStore class provides ways to execute fetch and save requests. There are a few recommended ways you can implement these requests in your app to load contacts:

  • Fetch only the contact properties that will be used.

  • When fetching all contacts and caching the results, first fetch all contacts identifiers, then fetch batches of detailed contacts by identifiers as required.

  • To aggregate several contacts fetches, first collect a set of unique identifiers from the fetches. Then fetch batches of detailed contacts by those unique identifiers.

  • If you cache the fetched contacts, groups, or containers, you need to refetch these objects (and release the old cached objects) when CNContactStoreDidChangeNotification is posted.

Because CNContactStore fetch methods perform I/O, it’s recommended that you avoid using the main thread to execute fetches.

Symbols

Fetching Unified Contacts

func unifiedMeContactWithKeys(toFetch: [CNKeyDescriptor])

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

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

Fetches a unified contact for the specified contact identifier.

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

Fetches all unified contacts matching the specified predicate.

Privacy Access

class func authorizationStatus(for: CNEntityType)

Returns the current authorization status to access the contact data.

Fetching and Saving

func groups(matching: NSPredicate?)

Fetches all groups matching the specified predicate.

func containers(matching: NSPredicate?)

Fetches all containers matching the specified predicate.

func defaultContainerIdentifier()

Returns the identifier of the default container.

func enumerateContacts(with: CNContactFetchRequest, usingBlock: (CNContact, UnsafeMutablePointer<ObjCBool>) -> Void)

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

func execute(CNSaveRequest)

Executes a save request and returns success or failure.

Constants

CNEntityType

The entities the user can grant access to.

CNAuthorizationStatus

An authorization status the user can grant for an app to access the specified entity type.

CNContactStoreDidChangeNotification

The notification posted when changes occur in another CNContactStore.

Relationships

Inherits From

Conforms To