Store custom label and date in Contact

196 Views Asked by At

I'm trying to store a custom label and associated date in a Contact. This is my code:

let contact = CNMutableContact()
let customLabel = "Label"
let customDate = DateComponents(year:1980, month:1, day:1)
contact.dates.append(CNLabeledValue<DateComponents>(label:customLabel, value:customDate))

The resulting error (on the last line) is:

"Type 'DateComponents' does not conform to protocol 'NSCopying'"

Any help would be appreciated.

1

There are 1 best solutions below

0
rmaddy On BEST ANSWER

The dates property takes an array of CNLabeledValue<NSDateComponents>.

You need to adjust your code just a bit in the last line to use NSDateComponents:

let contact = CNMutableContact()
let customLabel = "Label"
let customDate = DateComponents(year:1980, month:1, day:1)
contact.dates.append(CNLabeledValue<NSDateComponents>(label:customLabel, value:customDate as NSDateComponents))