Reputation:
I'm using this code for getting the name of the contact in swift this code give me character but I want string
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
contacts.forEach { (contact) in
for name in contact.givenName{
let contactName = name
nameLabel.text = String (contactName)
print(contactName)
}
}
}
Upvotes: 1
Views: 189
Reputation: 3373
givenName
is already a string; you don't have to loop through it.
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
guard let selectedContact = contacts.first else { return }
nameLabel.text = selectedContact.givenName
}
Upvotes: 2