iOS: CNContactPicker didSelect - How to determine the type of property selected?

333 Views Asked by At

I'm trying detect what type of property a user has selected when they've interacted with the CNContactPickerViewController by examining the CNContactProperty that gets passed to the protocol function the contact picker is done.

IE. To tell whether the user has selected a phone number, or an email, etc.

public func contactPicker(_ picker: CNContactPickerViewController, didSelect theContactProperty: CNContactProperty){

    if theContactProperty. == CNContactPhoneNumbersKey { // This doesn't work!!
        // Do stuff when we've received a phone number
    }
    else { 
        // Do other stuff when we have received something other than a phone number
    }
}

The "if" statement I've used above doesn't work. Any idea why?

How do I determine what type of property a user has selected from the contact picker screen?

1

There are 1 best solutions below

0
On BEST ANSWER

Solution:

if theContactProperty.key == CNContactPhoneNumbersKey {

}