Capture GivenName from CNContact

232 views Asked by At

I'm trying to capture the given name of a contact when the user selects that contact from the Contact Picker. Right now I'm using this method

 func contactPicker(_: CNContactPickerViewController, didSelect: CNContact){
    print("Selected Contact")

}

It works but I don't see how I can get a reference to the contact object that was selected. I was trying to reference these properties CNContact

1

There are 1 answers

0
Thomas G. On

The second parameter is the selected CNContact object. Note the contact next to the didSelect which is missing in your example. In your example you have to use didSelect parameter which is your CNContact but contact would be a much more expressive name.

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {

   print(contact.givenName)

}