I tried to use [MagicalRecord saveInBackgroundUsingCurrentContextWithBlock:....] in my gcd queue, and I realized that the managed object context had been stored to threadDictionary. However, gcd queue doesn't have a specific thread, and it doesn't have a unique context.
thx for reply. I just tried to write some code about the issue. I wonder if it would be correct.
static const NSString *kMRMOCKey = @"moc";
CFDictionaryRef dictCF = (CFDictionaryRef)dispatch_queue_get_specific(q, (__bridge CFStringRef)kMRMOCKey);
NSManagedObjectContext *qContext = [(__bridge NSDictionary *)dictCF objectForKey:@"obj"];
if (qContext == nil)
qContext = [self MR_contextWithParent:[NSManagedObjectContext MR_defaultContext]];
NSDictionary *dic = [NSDictionary dictionaryWithObject:qContext forKey:@"obj"];
CFDictionaryRef dictCF = CFDictionaryCreateCopy(NULL, (__bridge CFDictionaryRef)dic);
dispatch_queue_set_specific(q, (__bridge CFStringRef)kMRMOCKey, (void *)dictCF, (dispatch_function_t)CFRelease);
Storing contexts per thread in the thread’s dictionary is being deprecated in MagicalRecord 3.0. Thanks for the suggestion!