Skip to content
Browse files

Using descriptive macros to help imply reason for certain method call…

…s, ie. initWithConcurrencyType:
  • Loading branch information...
1 parent ac1135c commit db986748c4b35ebb4287f90731261f0d16016591 @casademora casademora committed Dec 8, 2011
Showing with 43 additions and 15 deletions.
  1. +27 −6 Source/Categories/NSManagedObjectContext+MagicalRecord.m
  2. +16 −9 Source/CoreData+MagicalRecord.h
View
33 Source/Categories/NSManagedObjectContext+MagicalRecord.m
@@ -38,6 +38,7 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
MR_RELEASE(defaultManageObjectContext_);
defaultManageObjectContext_ = moc;
+
[defaultManageObjectContext_ MR_observeiCloudChangesInCoordinator:coordinator];
}
@@ -259,10 +260,16 @@ + (NSManagedObjectContext *) MR_contextWithStoreCoordinator:(NSPersistentStoreCo
if (coordinator != nil)
{
MRLog(@"Creating MOContext %@", [NSThread isMainThread] ? @" *** On Main Thread ***" : @"");
- context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
- [context performBlockAndWait:^{
- [context setPersistentStoreCoordinator:coordinator];
- }];
+ THREAD_ISOLATION_ENABLED(
+ context = [[NSManagedObjectContext alloc] init];
+ [context setPersistentStoreCoordinator:coordinator];
+ )
+ PRIVATE_QUEUES_ENABLED(
+ context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
+ [context performBlockAndWait:^{
+ [context setPersistentStoreCoordinator:coordinator];
+ }];
+ )
MR_AUTORELEASE(context);
}
@@ -283,8 +290,22 @@ + (NSManagedObjectContext *) MR_context;
+ (NSManagedObjectContext *) MR_contextThatNotifiesDefaultContextOnMainThread;
{
- NSManagedObjectContext *context = [self MR_context];
- context.MR_notifiesMainContextOnSave = YES;
+ NSManagedObjectContext *context = nil;
+
+ THREAD_ISOLATION_ENABLED
+ (
+ context = [self MR_context];
+ context.MR_notifiesMainContextOnSave = YES;
+ )
+
+ PRIVATE_QUEUES_ENABLED
+ (
+ context = [[self alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
+ [context performBlockAndWait:^{
+ [context setPersistentStoreCoordinator:[NSPersistentStoreCoordinator MR_defaultStoreCoordinator]];
+ }];
+ )
+
return context;
}
View
25 Source/CoreData+MagicalRecord.h
@@ -4,11 +4,7 @@
#define kCreateNewCoordinatorOnBackgroundOperations 0
-#ifndef ENABLE_ACTIVE_RECORD_LOGGING
-#define ENABLE_ACTIVE_RECORD_LOGGING
-#endif
-
-#ifdef ENABLE_ACTIVE_RECORD_LOGGING
+#ifdef MR_ENABLE_LOGGING
#ifdef LOG_VERBOSE
#define MRLog(...) DDLogVerbose(__VA_ARGS__)
#else
@@ -24,11 +20,22 @@
#define MR_USE_ARC 1
#endif
-#if MR_USE_ARC
+#define PRIVATE_QUEUES_ENABLED(...) \
+ if (NSCoreDataVersionNumber >= NSCoreDataVersionNumber_iPhoneOS_4_0) \
+ { \
+ __VA_ARGS__ \
+ }
-#define MR_RETAIN(xx)
-#define MR_RELEASE(xx)
-#define MR_AUTORELEASE(xx)
+#define THREAD_ISOLATION_ENABLED(...) \
+ if (NSCoreDataVersionNumber < NSCoreDataVersionNumber_iPhoneOS_4_0) \
+ { \
+ __VA_ARGS__ \
+ }
+
+#if MR_USE_ARC
+#define MR_RETAIN(xx)
+#define MR_RELEASE(xx)
+#define MR_AUTORELEASE(xx)
#else
#define MR_RETAIN(xx) [xx retain];
#define MR_RELEASE(xx) [xx release];

0 comments on commit db98674

Please sign in to comment.
Something went wrong with that request. Please try again.