-1

I can't find a proper reference to Contacts framework by Apple, so I'm struggling with this problem, I need to fill the TableView with contacts having at least one email address, ContactsPickerController is not the solution, I need tableview to be filled right at viewDidLoad(). Can anyone please provide a solution for my problem.

1 Answers1

-1

You can get contact like this:

Reference -> https://stackoverflow.com/a/37388443/7512091

var contacts = [CNContact]()
let keys = [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)]
let request = CNContactFetchRequest(keysToFetch: keys)

do {
    try self.contactStore.enumerateContactsWithFetchRequest(request) {             
        (contact, stop) in
        // Array containing all unified contacts from everywhere
        contacts.append(contact)
    }
} 
catch {
    print("unable to fetch contacts")
}

This contact object's type is CNContact and it has a emailAddresses property which is an array of labeled email addresses for the contact.

Apple Reference: -> https://developer.apple.com/documentation/contacts/cncontact?language=objc

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
emrcftci
  • 3,355
  • 3
  • 21
  • 35