我想从我的应用程序更新我的实体(在 Swift 3 和 Xcode 8 中)。
所以我使用了核心数据模型。
这是我的 CoreDataController.swift 的代码:
// Updates a person
func update(updateLuci: LuciKit){
if let luci = getById(id: updateLuci.objectID){
luci.descrizione = updateLuci.descrizione
luci.pin_arduino = updateLuci.pin_arduino
}
}
// Gets a person by id
func getById(id: NSManagedObjectID) -> LuciKit? {
return context.object(with: id) as? LuciKit
}
在这种模式下我没有任何错误,但是如果我尝试重新启动我的应用程序我看不到更新信息。
最佳答案
试试这个我想你忘了保存上下文
func update(updateLuci: LuciKit){
if let luci = getById(id: updateLuci.objectID){
luci.descrizione = updateLuci.descrizione
luci.pin_arduino = updateLuci.pin_arduino
context.save()
}
}
关于iOS - 如何更新 CoreDataModel 实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43539853/