我是伟大框架的新手 Magical Record .
什么时候我必须为 MR 方法提供上下文?
示例:
// with context
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
CheckinTypes *checkinType = [CheckinTypes MR_createInContext:localContext];
// without context
CheckinTypes *checkinType1 = [CheckinTypes MR_createEntity];
这两种可能性有什么区别?
最佳答案
基本的经验法则是:
- 当您处于后台线程时,创建一个新上下文并在该上下文中执行您的工作。
然而,真正的答案要复杂得多。通常使用 Core Data 需要针对特定场景管理上下文。一个常见的场景是设置屏幕,其中设置保存在 Core Data 中。通过使用新的上下文,并在该上下文中进行更改,您可以简单地丢弃上下文(即不保存)它以删除用户尚未提交的任何临时更改。
Also, please note that MR_contextForCurrentThread has been deprecated and will be removed in an upcoming release of MagicalRecord. Using this method will lead to occasional, hard to track down crashes.
关于ios - 我什么时候必须给 Magical Record 一个上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21558093/