IOS 10+;持久性存储容器将父上下文设置为主上下文
遵循一个完美的核心数据堆栈,我们遵循这个层次结构 对于IOS 10+,苹果推出了IOS 10+;持久性存储容器将父上下文设置为主上下文,ios,swift,core-data,nsmanagedobjectcontext,nspersistentstore,Ios,Swift,Core Data,Nsmanagedobjectcontext,Nspersistentstore,遵循一个完美的核心数据堆栈,我们遵循这个层次结构 对于IOS 10+,苹果推出了NSPersistentContainer。 其中苹果描述了通过 let backgroundcontext = persistentContainer.newBackgroundContext() 主要内容如下: let maincontext = persistentContainer.viewContext 而NSPersistentContainer与此backgroundcontext关联。因此,此上
NSPersistentContainer
。
其中苹果描述了通过
let backgroundcontext = persistentContainer.newBackgroundContext()
主要内容如下:
let maincontext = persistentContainer.viewContext
而NSPersistentContainer
与此backgroundcontext
关联。因此,此上下文上的任何保存操作都将传递给NSPersistentStoreCoordinator
我的问题是如何遵循图中提到的层次结构?没有教程提到更改maincontext
的父上下文
意味着在backgroundcontext
中保存,并且maincontext
将对NSPersistentStoreCoordinator
执行I/O操作
完美的CoreData堆栈应该是这样的
在maincontext中保存将在backgroundcontext中保存。backgroundcontext上的保存操作将数据保存到NSPersistentStoreCoordinator。
如何做到这一点?检查此项