取回當我嘗試對背景上下文獲取它說: [的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