gpt4 book ai didi

swift - 在联系人中存储自定义标签和日期

转载 作者:行者123 更新时间:2023-11-30 11:45:30 24 4
gpt4 key购买 nike

我正在尝试在联系人中存储自定义标签和关联日期。这是我的代码:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com