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

标签 swift contacts-framework

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

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/

相关文章:

ios - iOS 9.2 上的游戏中心崩溃应用程序

arrays - 在 Swift 4.2 中从 String 创建 Modal 类

swift - 使用联系人框架 api ios 获取当前电话号码

ios - 删除号码电话联系人 - Swift 3 - 4

swift - 如何组合两个 DisposeBags?

ios - Swift:将 UIButton 用作 UIImage

swift - map View 不以当前用户位置为中心

IOS9 联系人框架无法更新链接的联系人

iphone - iOS 8上的UI框架崩溃

ios - 在ios联系人框架中如何确定要发短信的号码?