【发布时间】:2015-05-08 17:23:22
【问题描述】:
这是MyApp.xcdatamodeld,很简单:
_
这是与实体关联的类:
class LogItem: NSManagedObject {
@NSManaged var title: String
@NSManaged var itemText: String
@NSManaged var itemRank: String
}
现在这是导致错误的代码:
let newItem = NSEntityDescription.insertNewObjectForEntityForName("LogItem", inManagedObjectContext: self.managedObjectContext!) as! LogItem
newItem.title = "the title of the item"
newItem.itemText = "je suis chérif"
newItem.itemRank = "2" // this line causes an error !
最后是错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[MyApp.LogItem setItemRank:]: unrecognized selector sent to instance 0x155a8e30'
我做错了什么?
【问题讨论】:
-
我看不到明显的错误。如果删除那一行,代码是否可以正常运行?您确定在创建
class LogItem之后没有更改 Core Data 模型(或创建另一个版本)吗? -
我在创建类 LogItem 后对其进行了修改。我清理了项目,现在它可以工作了!所以实际上根本没有错误。
标签: ios swift core-data xcode6