- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我读了一些文章,但仍然没有得出结论。假设我有一个嵌套的 NSManagedObjectContext
像
BackgroundContext -> NSPrivateQueueConcurrencyType
|
child
v
MianContext -> NSMainQueueConcurrencyType
|
child
v
TemporaryContext -> NSPrivateQueueConcurrencyType
NSManagedObjectContextObjectsDidChangeNotification
并合并更改,例如:
- (void)managedObjectContextDidChanged:(NSNotification *)notification{
NSManagedObjectContext *currentContext = [notification object];
NSManagedObjectContext *mainConetext = [self mainThreadContext];
if (currentContext != mainConetext) {
[mainConetext performBlock:^{ //performBlock in notification
[mainConetext mergeChangesFromContextDidSaveNotification:notification];
}];
}
}
mainContext
上执行提取时,它表现良好。 ,但我感到困惑的是
mainContext如何合并子上下文变化 ,因为我觉得我在这里做错了什么。
performBlock
合并更改??
[temporaryContext performBlock:^(
//do some thing
[mainContext performBlock:^(
// merge changes
)];
)];
最佳答案
保存子上下文时,这些更改会自动推送到父上下文。正如 docs 中所说,您可以将上下文堆栈视为在根部具有持久存储协调器。保存的更改会向上推一级:
When you save changes in a context, the changes are only committed “one store up.” If you save a child context, changes are pushed to its parent. Changes are not saved to the persistent store until the root context is saved. (A root managed object context is one whose parent context is nil.) In addition, a parent does not pull changes from children before it saves. You must save a child context if you want ultimately to commit the changes.
关于ios - 具有嵌套 PerformBlock 的核心数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21643115/
我实现了一个搜索,对于用户输入的每个新字符,一个 performFetch:在 performBlock: 内部开始.如果搜索字符串发生变化,我想取消之前开始的 block 并重新开始。我将如何取消或
确实是一个简单的问题,我的核心数据 UIManagedDocument 是在主线程上创建的,我想知道的是当我调用 performBlock 时是否在主线程(创建托管文档的同一线程)上阻塞队列/运行?
我正在创建一个 NSManagedObjectContext在私有(private)队列中处理我从文件和/或服务中获取的数据更新: NSManagedObjectContext *privateCon
我读了一些文章,但仍然没有得出结论。假设我有一个嵌套的 NSManagedObjectContext像 BackgroundContext -> NSPrivateQueueConcurrencyT
使用 performBlock 在同一个私有(private)队列 NSManagedObjectContext 上同时调用 countForFetchRequest 两次时,我的 iOS 应用程序崩
我有流程,我应该创建对象并将其保存在 CoreData 中。但是按照流程,我需要每 X 秒更新一次对象并使用保存的上下文更新它。并且因为有可能终止 coredata 中的应用程序应该是对象的“最后更新
我最近开始尝试 Core Data 较新的托管对象上下文的 initWithConcurrencyType:NSPrivateQueueConcurrencyType 构造。当使用这种类型的 MOC
我使用 CoreData 并尝试发出异步获取请求。请解释一下,为什么我应该在那种情况下使用“performBlock”方法 [managedObjectcontext performBlock:^{
我读了这个article在后台将对象保存在 Core Data 数据库中。 在文章的最后,他们有这段代码可以在后台保存数据: [temporaryContext performBlock:^{
如果我使用 performBlock 保存 managedObjectContext,如何返回保存在 coredata 中的新对象? 需求是,在coredata中添加一个entry,并返回。我的代码是
当为 NSManagedObjectContext 使用 NSPrivateQueueConcurrencyType 和 NSMainQueueConcurrencyType 类型时,在同一上下文中进
假设我有一个与主线程相关的托管对象上下文,我调用 [mainContext performBlock:block]在主线程上。它会同步运行还是仍然计划并在以后运行? 最佳答案 假设您的意思是 NSMa
我正在使用 performBlock: 和 performBlockAndWait: 方法在我的上下文中的只读数据库上执行获取请求(它与我的应用程序打包在一起,因此从未写入)。 我是否也应该将每个 N
我之前已经看过这个问题,但是在我的情况下,所有解决方案似乎都没有影响,这是: 我的应用程序使用三个ManagedObjectContexts: 1)在全局(后台)队列上创建具有NSPrivateQue
我正在使用父/子并发模式来导入大数据 block 。导入在后台执行,不会阻塞主线程,如下所示: NSManagedObjectContext *temporaryContext = [[NSManag
长期以来,我一直在将 Core Data 与单个 NSManagedObjectContext 结合使用,所有获取、保存、后台更新操作都将通过辅助类在单个上下文中完成,我计划实现多个NSManaged
我正在使用 GCD 进行一些后台处理,并使用 Core Data 保存一些对象。在方法 [self saveData] 中,我创建一个具有并发类型 NSPrivateQueueConcurrencyT
我只是想弄清楚核心数据私有(private)上下文。我正在尝试使用私有(private)上下文 (NSPrivateQueueConcurrencyType) 插入 20k 记录。但是只要点击“插入
我想做的是在后台线程上创建一个异步核心数据任务,以免占用主线程,但我也想在工作完成后做主线程工作... 这是我的任务 -(void)doTaskwithCompletion:(coreDataCo
根据 WWDC 2012 视频“核心数据最佳实践”,dispatch_sync 应该用于在上下文的 performBlock 中运行某种回调,创建为一种 NSPrivateQueueConcurren
我是一名优秀的程序员,十分优秀!