gpt4 book ai didi

iOS 核心数据 : error when assigning a value to an attribute

转载 作者:行者123 更新时间:2023-11-28 09:08:37 24 4
gpt4 key购买 nike

这是 MyApp.xcdatamodeld,非常简单:

_ enter image description here

这是与实体关联的类:

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'

我做错了什么?

最佳答案

当我使用核心数据对象时,我使用以下代码行创建实体。

let logEntity = NSEntityDescription.entityForName("LogItem", inManagedObjectContext: self.managedObjectContext!)
let newItem = LogItem(entity: logEntity!, insertIntoManagedObjectCntext: self.managedObjectContext!)

newItem.title = "the title of the item"
newItem.itemText = "je suis chérif"
newItem.itemRank = "2"

然后保存上下文。

关于iOS 核心数据 : error when assigning a value to an attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30129482/

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