取回当我尝试对背景上下文获取它说: [的NSManagedObjectContext Multithreading_Violation_AllThatIsLeftToUsIsHonor()核心数据进行的performBlock在后台线程
在后台线程,我要检查如果一个对象存在然后更新。如果它不,我插入它,然后更新。出于某种原因,当我尝试执行提取操作时,xcode一直说我有并发冲突。我不允许在后台执行提取操作吗?
这是我对我的背景设置:
Persistent store -> Root saving context -> default context (concurrency type main) persistent store -> Root saving context -> background context (concurrency type private)
背景方面正试图performBlock:
NSManagedObjectContext *backgroundContext = [NSManagedObjectContext MR_context];
[backgroundContext performBlock:^{
[Conversation parseConversationAndCalls:objects inContext:backgroundContext];
...
}];
那么parseConversationAndCalls
方法调用将进行获取:
+ (void) parseConversationAndCalls:(NSArray*)objects inContext:(NSManagedObjectContext*)localContext {
...
for (NSArray *callData in conversationsCallData) {
NSNumber *callID = [BPDObject scrubbedInteger:callData[1]];
Call *call = (Call*) [FetchRequestHelper fetchWithClass:Call.self withID:callID inContext:localContext]; // breakpoint hit here
if (call == nil) {
call = [Call insertInManagedObjectContext:localContext];
}
[call updateWithValues:callData inContext:localContext];
call.contact = contact;
}
}
fetchrequest helpe [R只是创建了一个获取请求,FRC,然后执行获取在performBlock块:
... //here context is the same as backgroundContext and frc is the fetched results controller
context.performAndWait {
do {
try frc.performFetch()
} catch {
fatalError("Failed to perform fetch from FetchedResultsController: \(error)")
}
}
任何帮助将不胜感激
你可能是对的。我结束了使用没有FRC的提取请求,并且工作正常。 – Minimi