swiftcncontactcncontactstore

Company field when enumerating contacts through CNContactStore


I'm fetching some contact fields using CNContactStore such as first name (CNContactGivenNameKey) and last name (CNContactFamilyNameKey) but I can't find the key for company.

let request = CNContactFetchRequest(keysToFetch: [
  CNContactGivenNameKey as NSString,
  CNContactFamilyNameKey as NSString,
])

request.sortOrder = .familyName

do {
  let store = CNContactStore()
  try store.enumerateContacts(with: request) { contact, stop in
    // ...
  }
} catch {
  print(error)
}

Solution

  • The key is CNContactOrganizationNameKey.

    The confusion comes from the fact that the Contacts app (in all iOS, iPadOS and macOS) use the word company while the key refers to it as organization, making it hard to find through auto-complete in Xcode, or when searching for it in Google or Stack Overflow.