Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only create action queue on demand

Small cleanup
  • Loading branch information...
commit 1f4f06b3b488986a799e6580858abbe850feb35f 1 parent e4cd170
@casademora casademora authored
View
2  MagicalRecord/Categories/NSPersistentStoreCoordinator+MagicalRecord.m
@@ -10,7 +10,7 @@
static NSPersistentStoreCoordinator *defaultCoordinator_ = nil;
NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification = @"kMagicalRecordPSCDidCompleteiCloudSetupNotification";
-@interface NSDictionary (Merging)
+@interface NSDictionary (MagicalRecordMerging)
- (NSMutableDictionary*) MR_dictionaryByMergingDictionary:(NSDictionary*)d;
View
25 MagicalRecord/Core/MagicalRecord+Actions.m
@@ -9,21 +9,36 @@
#import "CoreData+MagicalRecord.h"
#import "NSManagedObjectContext+MagicalRecord.h"
-static dispatch_queue_t action_queue;
+static dispatch_queue_t background_action_queue;
-@implementation MagicalRecord (Actions)
+dispatch_queue_t action_queue(void);
+dispatch_queue_t action_queue(void)
+{
+ if (background_action_queue == NULL)
+ {
+ background_action_queue = dispatch_queue_create("com.magicalpanda.magicalrecord.actionQueue", DISPATCH_QUEUE_SERIAL);
+ }
+ return background_action_queue;
+}
-+ (void) load;
+void reset_action_queue(void);
+void reset_action_queue(void)
{
- action_queue = dispatch_queue_create("com.magicalpanda.magicalrecord.actionQueue", DISPATCH_QUEUE_SERIAL);
+ if (background_action_queue != NULL)
+ {
+ dispatch_release(background_action_queue);
+ background_action_queue = NULL;
+ }
}
+@implementation MagicalRecord (Actions)
+
+ (void) saveInBackgroundWithBlock:(void (^)(NSManagedObjectContext *))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *))errorHandler;
{
NSManagedObjectContext *mainContext = [NSManagedObjectContext MR_defaultContext];
NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextWithParent:mainContext];
- dispatch_async(action_queue, ^{
+ dispatch_async(action_queue(), ^{
block(localContext);
if ([localContext hasChanges])
View
3  MagicalRecord/Core/MagicalRecord.h
@@ -12,8 +12,6 @@
// enable to use caches for the fetchedResultsControllers (iOS only)
// #define STORE_USE_CACHE
-#define kCreateNewCoordinatorOnBackgroundOperations 0
-
#ifndef MR_ENABLE_ACTIVE_RECORD_LOGGING
#ifdef DEBUG
#define MR_ENABLE_ACTIVE_RECORD_LOGGING 1
@@ -23,6 +21,7 @@
#endif
#if MR_ENABLE_ACTIVE_RECORD_LOGGING != 0
+ // First, check if we can use Cocoalumberjack for logging
#ifdef LOG_VERBOSE
extern int ddLogLevel;
#define MRLog(...) DDLogVerbose(__VA_ARGS__)
View
2  MagicalRecord/Core/MagicalRecord.m
@@ -19,6 +19,7 @@ + (void) MR_cleanUp;
@end
+void reset_action_queue(void);
@implementation MagicalRecord
@@ -26,6 +27,7 @@ + (void) cleanUp
{
[self cleanUpErrorHanding];
[self cleanUpStack];
+ reset_action_queue();
}
+ (void) cleanUpStack;
Please sign in to comment.
Something went wrong with that request. Please try again.