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.
Asked
Active
Viewed 336 times
-1

Rustam Tadjibaev
- 1
- 1
-
Check this https://stackoverflow.com/questions/33973574/fetching-all-contacts-in-ios-swift – Matias Jurfest Nov 10 '19 at 13:53
-
Fetch them all. Then display only the ones with email addresses. – Daniel Storm Nov 10 '19 at 14:00
1 Answers
-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