I need some help using APAddressBook.
I can't understand how to use APAddressBook to load and show contacts.
I think this function gets all contacts from address book
func loadContacts() {
self.addressBook.loadContacts({
(contacts: [APContact]?, error: NSError?) in
if let unwrappedContacts = contacts {
print(unwrappedContacts)
} else {
// show error...
And this function extracts names
func contactName(contact :APContact) -> String {
if let firstName = contact.name?.firstName, lastName = contact.name?.lastName {
return "\(firstName) \(lastName)"
}
else if let firstName = contact.name?.firstName {
return "\(firstName)"
}
else if let lastName = contact.name?.lastName {
return "\(lastName)"
}
else {
return "Unnamed contact"
}
}
What I don't understand how to display those names here:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("contacts", forIndexPath: indexPath) as! ContactsTableViewCell
// Configure the cell...
cell.contactsNumberLabel.text = contactsListNumbers[indexPath.row]
cell.contactsNameLabel.text = contactListNames[indexPath.row]
return cell
}