Permalink
Browse files

Merge branch 'private_queue_constant' of github.com:fossli/MagicalRec…

…ord into private_queue_constant
  • Loading branch information...
2 parents 9d95747 + 8123d3a commit 4216a83dde60d2280628a41f51dd15aa260f81e9 @hfossli hfossli committed Mar 27, 2012
@@ -32,6 +32,10 @@ extern NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification;
+ (void) MR_setDefaultContext:(NSManagedObjectContext *)moc;
+ (void) MR_resetContextForCurrentThread;
+#if TEST
++ (void)resetContextMap;
+#endif
+
+ (NSManagedObjectContext *) MR_context;
+ (NSManagedObjectContext *) MR_contextForCurrentThread;
@@ -13,6 +13,11 @@
static void const * kMagicalRecordNotifiesMainContextAssociatedValueKey = @"kMagicalRecordNotifiesMainContextOnSave";
NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification = @"kMagicalRecordDidMergeChangesFromiCloudNotification";
+#if TEST
+static NSMutableDictionary *contextMap;
+#endif
+
+
@interface NSManagedObjectContext (MagicalRecordPrivate)
- (void) MR_mergeChangesFromNotification:(NSNotification *)notification;
@@ -276,7 +281,21 @@ + (NSManagedObjectContext *) MR_contextForCurrentThread;
}
else
{
- NSManagedObjectContext *context = [self MR_contextThatNotifiesDefaultContextOnMainThread];
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ contextMap = [[NSMutableDictionary alloc] init];
+ });
+
+ if([[NSThread currentThread] name] == nil || [[[NSThread currentThread] name] isEqualToString:@""]){
+ [[NSThread currentThread] setName:[NSString stringWithFormat:@"%i", [[NSDate date] timeIntervalSince1970]]];
+ }
+
+ NSManagedObjectContext *context = [contextMap objectForKey:[[NSThread currentThread] name]];
+
+ if(context == nil){
+ context = [self MR_contextThatNotifiesDefaultContextOnMainThread];
+ [contextMap setObject:context forKey:[[NSThread currentThread] name]];
+ }
return context;
}
@@ -303,6 +322,15 @@ + (NSManagedObjectContext *) MR_contextForCurrentThread;
}
+#if TEST
++ (void)resetContextMap{
+
+ [contextMap release];
+ contextMap = [[NSMutableDictionary alloc] init];
+
+}
+#endif
+
+ (NSManagedObjectContext *) MR_contextWithStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator;
{
NSManagedObjectContext *context = nil;

0 comments on commit 4216a83

Please sign in to comment.