Class

CNContact

A thread-safe class that represents an immutable value object for contact properties, such as the first name and phone numbers of a contact.

Overview

CNContact is similar to a complex Foundation collection, in that it has a mutable subclass (CNMutableContact). Neither the CNContact nor CNMutableContact class maintain a reference to their data store. Every contact has a unique ID, which you obtain using the identifier property.

Topics

Identification Properties

var identifier: String

A value that uniquely identifies a contact on the device.

var contactType: CNContactType

An enum identifying the contact type.

Date Properties

var birthday: DateComponents?

A date component for the Gregorian birthday of the contact.

var nonGregorianBirthday: DateComponents?

A date component for the non-Gregorian birthday of the contact.

var dates: [CNLabeledValue<NSDateComponents>]

An array containing labeled Gregorian dates.

Name Properties

var namePrefix: String

The name prefix of the contact.

var givenName: String

The given name of the contact.

var middleName: String

The middle name of the contact.

var familyName: String

The family name of the contact.

var previousFamilyName: String

A string for the previous family name of the contact.

var nameSuffix: String

The name suffix of the contact.

var nickname: String

The nickname of the contact.

var phoneticGivenName: String

The phonetic given name of the contact.

var phoneticMiddleName: String

The phonetic middle name of the contact.

var phoneticFamilyName: String

A string for the phonetic family name of the contact.

var organizationName: String

The name of the organization associated with the contact.

var departmentName: String

The name of the department associated with the contact.

var jobTitle: String

The contact’s job title.

Localization

class func localizedString(forKey: String)

Returns a string containing the localized contact property name.

Contact Comparator

class func descriptorForAllComparatorKeys()

Fetches all the keys required for the contact sort comparator.

class func comparator(forNameSortOrder: CNContactSortOrder)

Returns a comparator to sort contacts with the specified order.

Social Properties

var socialProfiles: [CNLabeledValue<CNSocialProfile>]

An array of labeled social profiles for a contact.

Contact phone Number

var phoneNumbers: [CNLabeledValue<CNPhoneNumber>]

An array of labeled phone numbers for a contact.

Url Address

var urlAddresses: [CNLabeledValue<NSString>]

An array of labeled URL addresses for a contact.

Postal Addresses

var postalAddresses: [CNLabeledValue<CNPostalAddress>]

An array of labeled postal addresses for a contact.

Email Address

var emailAddresses: [CNLabeledValue<NSString>]

An array of labeled email addresses for the contact.

Note Property

var note: String

A string containing notes for the contact.

Image Properties

var imageData: Data?

The profile picture of a contact.

var thumbnailImageData: Data?

The thumbnail version of the contact’s profile picture.

var imageDataAvailable: Bool

Indicates whether a contact has a profile picture.

Labeled Value Properties

var contactRelations: [CNLabeledValue<CNContactRelation>]

An array of labeled relations for the contact.

var instantMessageAddresses: [CNLabeledValue<CNInstantMessageAddress>]

An array of labeled IM addresses for the contact.

Partial Contact property availability

func isKeyAvailable(String)

Determines whether the contact property value for the specified key is fetched.

func areKeysAvailable([CNKeyDescriptor])

Determines whether all contact property values for the specified keys are fetched.

CNContact Predicates

Predicates to match contacts. You can only use these predicates with CNContactStore and CNContactFetchRequest.

class func predicateForContacts(matchingName: String)

Returns a predicate to find the contacts matching the specified name.

class func predicateForContacts(withIdentifiers: [String])

Returns a predicate to find the contacts matching the specified identifiers.

class func predicateForContactsInGroup(withIdentifier: String)

Returns a predicate to find the contacts that are members in the specified group.

class func predicateForContactsInContainer(withIdentifier: String)

Returns a predicate to find the contacts in the specified container.

Constants

enum CNContactType

The types a contact can be.

enum CNContactSortOrder

Indicates the sorting order for contacts.

Exception Handling

Exception thrown when accessing a properties that was not fetched.

Identifier

Identifiers for properties that are always fetched.

Metadata Keys

A set of predefined keys representing contact properties that can be used with key value coding on CNContact objects.