I tried this:
let contact = CNMutableContact()
contact.namePrefix = data["firstName"] as! String
contact.nameSuffix = data["lastName"] as! String
contact.organizationName = data["company"] as! String
contact.jobTitle = data["jobTitle"] as! String
let address = CNMutablePostalAddress()
address.street = data["street"] as! String
address.city = data["city"] as! String
address.state = data["state"] as! String
address.postalCode = data["zipcode"] as! String
address.country = data["country"] as! String
contact.postalAddresses = [address]
And I received this error:
Cannot convert value of type 'CNMutablePostalAddress' to expected element type 'CNLabeledValue<CNPostalAddress>'
So, I tried this:
let contact = CNMutableContact()
contact.namePrefix = data["firstName"] as! String
contact.nameSuffix = data["lastName"] as! String
//contact.birthday =
contact.organizationName = data["company"] as! String
contact.jobTitle = data["jobTitle"] as! String
let street = CNLabeledValue(label: "street", value:data["street"] as! NSString)
let city = CNLabeledValue(label: "city", value:data["city"] as! NSString)
let state = CNLabeledValue(label: "state", value:data["state"] as! NSString)
let postalCode = CNLabeledValue(label: "zipcode", value:data["zipcode"] as! NSString)
let country = CNLabeledValue(label: "country", value:data["country"] as! NSString)
contact.postalAddresses = [street, city, state, postalCode, country]
And I received this error:
Cannot convert value of type 'CNLabeledValue<NSString>' to expected element type 'CNLabeledValue<CNPostalAddress>'
And I don't know how to create CNLabeledValue<CNPostalAddress>
.
Do you know the right way to create a CNContact
with a CNPostalAddress
?
You are mistaking the usage of
CNLabeledValue
. Try this: