【发布时间】:2016-05-25 17:26:43
【问题描述】:
大家早上好,我学习了这个教程 我可以添加新联系人并检索现有联系人,但我想要完成的是将添加的列表保存在 mutableArray 中并使用该数组填充我的 TableView。我收到此错误
联系人介绍[5166:4971615] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“尝试插入非属性列表对象( "!$_, value=>\"\n), emailAddresses=(\n \"!$_, value=>\"\n), postalAddresses=(\n)>" ) 为关键联系人Key'
这里
func insertNewObject(sender: NSNotification) {
print("How Many Times am I getting here ??")
if let contact = sender.userInfo?["contactToAdd"] as? CNContact {
objects.insert(contact, atIndex: 0)
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
print("How Many Objects ",objects.count)
let contactArray = objects as [CNContact]
let prefs = NSUserDefaults.standardUserDefaults()
prefs.setValue(contactArray, forKey: "contactsKey")
}
任何帮助表示赞赏。
问候 江泽
【问题讨论】:
-
要将对象数组保存在用户默认值中,对象必须是对属性列表有效的类型。 (developer.apple.com/library/mac/documentation/Cocoa/Conceptual/…) 你能改用联系人的
identifier字符串吗(并在需要时查找联系人)?