我正在尝试在联系人中存储自定义标签和关联日期。这是我的代码:
let contact = CNMutableContact()
let customLabel = "Label"
let customDate = DateComponents(year:1980, month:1, day:1)
contact.dates.append(CNLabeledValue<DateComponents>(label:customLabel, value:customDate))
产生的错误(在最后一行)是:
“类型‘DateComponents’不符合协议(protocol)‘NSCopying’”
如有任何帮助,我们将不胜感激。
最佳答案
dates
属性采用 CNLabeledValue<NSDateComponents>
的数组.
您需要在最后一行稍微调整一下代码才能使用 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))
关于swift - 在联系人中存储自定义标签和日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48877498/