我正在使用新版Magical Records并遇到问题。不推荐使用MR_contextForCurrentThread的方法,我想找到新的上下文而不是那个,但是没有成功,我总是有错误。我已经尝试过简单的MR_Context和MR_rootSavingContext。在异步模式下使用哪种方法更好?
dispatch_async(_syncQueue, ^{
__unused YOUServerObject *o;
NSManagedObjectContext *moc = [NSManagedObjectContext MR_contextForCurrentThread];
[moc reset];
[moc performBlockAndWait:^{
NSArray *objects = [array bk_map:^id(NSDictionary *dict) {
// fetching from core data by path and id
return object;
}];
for (NSUInteger i = 0; i < array.count; ++i)
{
// sync relationshipsYOUSyncableServerObject in core data
// obj.syncDateTime = syncDate;
}
[moc MR_saveWithOptions:MRSaveSynchronously | MRSaveParentContexts
completion:^(BOOL contextDidSave, NSError *error) {
// saving inside core data
}];
}