Company field when enumerating contacts through CNContactStore

227 views Asked by At

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)
}
1

There are 1 answers

0
cbuchart On BEST ANSWER

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.