当我最后一次尝试更新实体时,我在 CoreData
中设置了 Entity
Type ' Settings.Type' has no subscript members error
我该如何解决? 如何从设置实体更新最后一行值
我的设置实体 属性;
id. = Integer32
name = String
age = String
我的代码在下面。
let appDelegate = UIApplication.shared.delegate as! AppDelegate
Settings[0].id = json["id"]["namesettings"].int32Value
Settings[0].name = json["name"]["name"].stringValue
Settings[0].age = json["age"]["age"].stringValue
appDelegate.saveContext()
Settings[0] 行出现此错误。
谢谢!
最佳答案
不知道这正是你想要的,但是为了更新 CoreData
Entity
你需要有 NSMangedObject
为此你需要首先从 CoreData
中获取记录。
let request: NSFetchRequest<Settings> = Settings.fetchRequest()
let settings = try! context.fetch(request)
//Now access the last object from it edit it
if let obj = settings.last {
obj.id = json["id"]["namesettings"].int32Value
obj.name = json["name"].stringValue
obj.age = json["age"].stringValue
appDelegate.saveContext()
}
关于ios - Coredata Update Entity last item Type ' Type' has no subscript members in Swift 3 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41956420/