user9050369
user9050369

Reputation:

how to convert a character to string in swift4?

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

Answers (1)

ouni
ouni

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

Related Questions