ios - CoreData saving objects earlier than expected
问题描述
I have a Match class using Core Data. In my view controller I create a Match instance in a context. I'm using and modifying the match object in the controller and then have a button that save the instance in context. But if I close the application without taping the save button, the Match instance is still saved.
Here's my object declaration:
class ViewController: UIViewController {
//(...)
let match = Match(context: AppDelegate.viewContext)
override func viewDidLoad() {
super.viewDidLoad()
}
//(...)
}
And here's my save fonction that is called by the button:
@IBAction func saveMatch() {
try? AppDelegate.viewContext.save()
self.dismiss(animated: true, completion: nil)
}
解决方案
查看您的其余代码以了解您调用的其他位置save()
。如果您在核心数据周围使用包装器,请搜索它们调用的位置save()
。您可能与applicationDidEnterBackground
. 添加断点save()
并查看调用它的内容。
推荐阅读
- java - Jsoup.body() 返回空正文
- javascript - 如何使用 forEach-Loop 将数组的内容转为另一个数组?
- powershell - 导出然后导入自定义的 WMI 命名空间
- android - 覆盖整个活动的底部导航视图
- java - java.jdbc clojure 执行!插入数量
- nuget - 我可以控制工件中_local_ repos 的顺序吗?
- node.js - nodeJS 子进程在 process.on(stdout) 和 process.on(exit) 之间的竞争条件
- c# - ASP.NET Core 2.0 app.UseAuthentication 未针对每个请求执行
- c# - 生成大量字节 [] 对象时 C# 中的 System.OutOfMemoryException
- javascript - 在我的项目中包含“布尔解析器”库(“未定义要求”)