Browse files

Merge branch 'release/2.0.8'

  • Loading branch information...
2 parents 58f463d + fb81b5b commit 8861927036a5784500a3c9dc84a3352eab57c6c5 @blackgold9 blackgold9 committed Nov 4, 2012
View
59 Changelog.md
@@ -0,0 +1,59 @@
+# Changelog
+## Version 2.0.8
+* Fixed issue #287 - MR_findByAttribute:withValue:andOrderBy:ascending:inContext does not pass context through `4b97d0e` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+## Version 2.0.7
+* Fix small error in README with regard to MR_SHORTHAND `8c14cc7` - [Maik Gosenshuis](mailto:maik@gosenshuis.nl)
+* Hide intended private cleanUpErrorHandling method `a903e7e` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Call completion handler on main thread. `c639ce4` - [Brandon Williams](mailto:brandon@opetopic.com)
+* Persist changes to disk when using: - [NSManagedObjectContext MR_saveInBackgroundErrorHandler:completion:] methods, AND the context is the default context - [MagicalRecord saveInBackground…] methods `8bb0d0d` - [Saul Mora](mailto:saul@magicalpanda.com)
+* [NSManagedObjectContext MR_saveInBackgroundErrorHandler:completion:] `f0246e9` - [Jwie](mailto:joey.daman@twoup.eu)
+* [NSManagedObjectContext MR_saveInBackgroundErrorHandler:completion:] `eabb147` - [Jwie](mailto:joey.daman@twoup.eu)
+* update `8b7c1c8` - [Peter Paulis](mailto:peterpaulis@Admins-MacBook-Air-2.local)
+* Correct typo `f99215b` - [Ryan Maxwell](mailto:ryanm@xwell.co.nz)
+* Update MR_SHORTHAND installation note to match main readme `222c956` - [Ryan Maxwell](mailto:ryanm@xwell.co.nz)
+* Correct typo of "persistent" in method name `86db065` - [Ryan Maxwell](mailto:ryanm@xwell.co.nz)
+* Make all requestAllSortedBy* methods consistent (allows sortTerms with commas) `33f3994` - [vguerci](mailto:vguerci@gmail.com)
+* dispatch_release is not needed by the <REDACTED> compiler `7128091` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Don't run completion block if non specified `3aa2845` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Make platform requirements more explicit `acff79a` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Update MagicalRecord/Core/MagicalRecordShorthand.h `7daf3ad` - [Ryan Maxwell](mailto:ryanm@xwell.co.nz)
+* Added automatic store deletion if the store does not match the model `b8326a6` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Missed the configuration `22fe81a` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Updating readme with a short blurb `d8394cf` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Cleanup code is now debug-only `45d764a` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Clarified the DEBUG only nature of the fix `8842d8f` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Making background save asynchronous and fix the callback not firing `22311b7` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Added expecta matchers for tests `cff0304` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Fixing formatting issues to match project style `3bc55de` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Fixed KVC relationship mapping bug. `eaa78c2` - [Joshua Greene](mailto:jrg.developer@gmail.com)
+* Fixed an issue with aggregate actions not being performed in the specified context `9348ef5` - [Brian King](mailto:bking@agamatrix.com)
+* Adding an observer to check for icloud being setup after default context has been set. Should fix race condition in Issue #241 `5341e84` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Updated test model to actually build `2df10b1` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Clean up comments `ef16c57` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Remove compile warnings `8f93070` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Cleaning up iCloud setup observer code some `32f9f80` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Removes dispatch_release when iOS >= 6 || OSX >= 1080 `28a864b` - [Rod Wilhelmy](mailto:rwilhelmy@gmail.com)
+* Modifiying generateShorthand.rb to use user specified ruby `25081d0` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Automatically obtain permanent IDs when saving the default context. This should fix several crashes the community is hitting `0e34179` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Making all relevant contexts obtain a permanent id before saving `0b00e39` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Adding recommended journalling mode `a9a7643` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* fixup compiler warnings in Xcode 4.5 `5203cc1` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Fix compile warnings once and for all :/ `11e5ee1` - [Saul Mora](mailto:saul@magicalpanda.com)
+* refactor internal method names to match more general objects to traverse fix another compile warning `0a6f523` - [Saul Mora](mailto:saul@magicalpanda.com)
+* - auto-migration options bug fix `1924d73` - [Alexander Belyavskiy](mailto:diejmon@me.com)
+* Don't adjust incoming NSDates for DST `da39710` - [Saul Mora](mailto:saul@magicalpanda.com)
+* fix compile error with pragma option `51fe465` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Add findFirstOrderedByAttribute:ascending:context: method for getting min/max values easier `abb7314` - [Saul Mora](mailto:saul@magicalpanda.com)
+* Bumping podspec to 2.0.4 `4091c78` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Added new nestedContextSave method with completion handler `2660e73` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Bumping podspec with bugfix `a451eb4` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Fixing rookie mistake :/ `72dc5a4` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Require ARC in podspec (was compiling with retain/release in pod installations) `48cc383` - [Ryan Maxwell](mailto:ryanm@xwell.co.nz)
+* Bump tag to 2.0.6 `f2e2b7b` - [Ryan Maxwell](mailto:ryanm@xwell.co.nz)
+* Properly removing existing on-save notificaitons before replacing the default or root contexts `343b027` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Fixing potential concurrency issue with creating the actionQueue `52139bd` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Cherry picking changes that make the context description more... descriptive `a41ceee` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* Rolled back a commit that broke things if cleanup was used. It created the action_queue in a dispatch_once block, and never recreated it after a cleanup `b81e70d` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
+* saveWithBlock was not saving parent contexts `870ca22` - [Tony Arnold](mailto:tony@thecocoabots.com)
+* Test that the current thread saveWith method actually saves `d41d744` - [Tony Arnold](mailto:tony@thecocoabots.com)
+* Bumped podspec to 2.0.7 `601869e` - [Stephen Vanterpool](mailto:stephen@vanterpool.net)
View
4 MagicalRecord.podspec
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = 'MagicalRecord'
- s.version = '2.0.7'
+ s.version = '2.0.8'
s.license = 'MIT'
s.summary = 'Super Awesome Easy Fetching for Core Data 1!!!11!!!!1!.'
s.homepage = 'http://github.com/magicalpanda/MagicalRecord'
s.author = { 'Saul Mora' => 'saul@magicalpanda.com' }
- s.source = { :git => 'https://github.com/magicalpanda/MagicalRecord.git', :tag => '2.0.7' }
+ s.source = { :git => 'https://github.com/magicalpanda/MagicalRecord.git', :tag => '2.0.8' }
s.description = 'Handy fetching, threading and data import helpers to make Core Data a little easier to use.'
s.source_files = 'MagicalRecord/**/*.{h,m}'
s.framework = 'CoreData'
View
3 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalFinders.h
@@ -42,6 +42,9 @@
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
++ (NSFetchedResultsController *) MR_fetchAllWithDelegate:(id<NSFetchedResultsControllerDelegate>)delegate;
++ (NSFetchedResultsController *) MR_fetchAllWithDelegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
+
+ (NSFetchedResultsController *) MR_fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id<NSFetchedResultsControllerDelegate>)delegate;
+ (NSFetchedResultsController *) MR_fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
View
18 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalFinders.m
@@ -1,4 +1,4 @@
-//
+ //
// NSManagedObject+MagicalFinders.m
// Magical Record
//
@@ -198,7 +198,7 @@ + (NSArray *) MR_findByAttribute:(NSString *)attribute withValue:(id)searchValue
NSPredicate *searchTerm = [NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue];
NSFetchRequest *request = [self MR_requestAllSortedBy:sortTerm ascending:ascending withPredicate:searchTerm inContext:context];
- return [self MR_executeFetchRequest:request];
+ return [self MR_executeFetchRequest:request inContext:context];
}
+ (NSArray *) MR_findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending
@@ -231,6 +231,20 @@ + (NSFetchedResultsController *) MR_fetchController:(NSFetchRequest *)request de
return controller;
}
++ (NSFetchedResultsController *) MR_fetchAllWithDelegate:(id<NSFetchedResultsControllerDelegate>)delegate;
+{
+ return [self MR_fetchAllWithDelegate:delegate inContext:[NSManagedObjectContext MR_contextForCurrentThread]];
+}
+
++ (NSFetchedResultsController *) MR_fetchAllWithDelegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
+{
+ NSFetchRequest *request = [self MR_requestAllInContext:context];
+ NSFetchedResultsController *controller = [self MR_fetchController:request delegate:delegate useFileCache:NO groupedBy:nil inContext:context];
+
+ [self MR_performFetch:controller];
+ return controller;
+}
+
+ (NSFetchedResultsController *) MR_fetchAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending delegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context
{
NSFetchRequest *request = [self MR_requestAllSortedBy:sortTerm
View
6 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalRequests.m
@@ -92,10 +92,10 @@ + (NSFetchRequest *) MR_requestFirstByAttribute:(NSString *)attribute withValue:
+ (NSFetchRequest *) MR_requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context
{
- return [self MR_requestAllSortedBy:sortTerm
+ return [self MR_requestAllSortedBy:sortTerm
ascending:ascending
- withPredicate:nil
- inContext:[NSManagedObjectContext MR_contextForCurrentThread]];
+ withPredicate:nil
+ inContext:context];
}
+ (NSFetchRequest *) MR_requestAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending
View
4 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.h
@@ -23,8 +23,8 @@ extern NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification;
+ (NSManagedObjectContext *) MR_defaultContext;
- (NSString *) MR_description;
+- (NSString *) MR_parentChain;
-- (void) MR_setContextWorkingName:(NSString *)workingName;
-- (NSString *) MR_contextWorkingName;
+@property (nonatomic, copy, setter = MR_setWorkingName:) NSString *MR_workingName;
@end
View
84 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.m
@@ -12,7 +12,7 @@
static NSManagedObjectContext *defaultManagedObjectContext_ = nil;
static id iCloudSetupNotificationObserver = nil;
-#define kNSManagedObjectContextWorkingName @"kNSManagedObjectContextWorkingName"
+static NSString * const kMagicalRecordNSManagedObjectContextWorkingName = @"kNSManagedObjectContextWorkingName";
@interface NSManagedObjectContext (MagicalRecordInternal)
@@ -34,19 +34,23 @@ + (void) MR_cleanUp;
- (NSString *) MR_description;
{
- NSString *contextName = (self == defaultManagedObjectContext_) ? @"*** DEFAULT ***" : @"";
- contextName = (self == rootSavingContext) ? @"*** BACKGROUND SAVE ***" : contextName;
-
- NSString *onMainThread = [NSThread isMainThread] ? @"*** MAIN THREAD ***" : @"*** SECONDARY THREAD ***";
-
- NSString *familyTree = [NSString string];
- NSManagedObjectContext *parentContext = [self parentContext];
- while (nil != parentContext) {
- familyTree = [familyTree stringByAppendingFormat:@" ==> %@;",[parentContext MR_contextWorkingName]];
- parentContext = [parentContext parentContext];
+ NSString *contextLabel = [NSString stringWithFormat:@"*** %@ ***", [self MR_workingName]];
+ NSString *onMainThread = [NSThread isMainThread] ? @"*** MAIN THREAD ***" : @"*** BACKGROUND THREAD ***";
+
+ return [NSString stringWithFormat:@"<%@ (%p): %@> on %@", NSStringFromClass([self class]), self, contextLabel, onMainThread];
+}
+
+- (NSString *) MR_parentChain;
+{
+ NSMutableString *familyTree = [@"" mutableCopy];
+ NSManagedObjectContext *currentContext = self;
+ do
+ {
+ [familyTree appendFormat:@"- %@ (%p) %@\n", [currentContext MR_workingName], currentContext, (currentContext == self ? @"(*)" : @"")];
}
+ while ((currentContext = [currentContext parentContext]));
- return [NSString stringWithFormat:@"%@: %@ Context %@ \nFamilyTree: %@", [self MR_contextWorkingName], contextName, onMainThread,familyTree];
+ return [NSString stringWithString:familyTree];
}
+ (NSManagedObjectContext *) MR_defaultContext
@@ -66,7 +70,8 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
}
NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
- if (iCloudSetupNotificationObserver) {
+ if (iCloudSetupNotificationObserver)
+ {
[[NSNotificationCenter defaultCenter] removeObserver:iCloudSetupNotificationObserver];
iCloudSetupNotificationObserver = nil;
}
@@ -77,8 +82,10 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
}
defaultManagedObjectContext_ = moc;
- [moc MR_obtainPermanentIDsBeforeSaving];
- if ([MagicalRecord isICloudEnabled])
+ [defaultManagedObjectContext_ MR_setWorkingName:@"DEFAULT"];
+
+// [moc MR_obtainPermanentIDsBeforeSaving];
+ if ([MagicalRecord isICloudEnabled])
{
[defaultManagedObjectContext_ MR_observeiCloudChangesInCoordinator:coordinator];
}
@@ -92,6 +99,7 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
[[NSManagedObjectContext MR_defaultContext] MR_observeiCloudChangesInCoordinator:coordinator];
}];
}
+ MRLog(@"Set Default Context: %@", defaultManagedObjectContext_);
}
+ (NSManagedObjectContext *) MR_rootSavingContext;
@@ -107,24 +115,23 @@ + (void) MR_setRootSavingContext:(NSManagedObjectContext *)context;
}
rootSavingContext = context;
- [context MR_obtainPermanentIDsBeforeSaving];
+// [context MR_obtainPermanentIDsBeforeSaving];
[rootSavingContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy];
- [rootSavingContext MR_setContextWorkingName:@"rootSavingsContext"];
+ [rootSavingContext MR_setWorkingName:@"BACKGROUND SAVING (ROOT)"];
+ MRLog(@"Set Root Saving Context: %@", rootSavingContext);
}
+ (void) MR_initializeDefaultContextWithCoordinator:(NSPersistentStoreCoordinator *)coordinator;
{
if (defaultManagedObjectContext_ == nil)
{
NSManagedObjectContext *rootContext = [self MR_contextWithStoreCoordinator:coordinator];
-
[self MR_setRootSavingContext:rootContext];
NSManagedObjectContext *defaultContext = [self MR_newMainQueueContext];
- [defaultContext MR_setContextWorkingName:@"defaultContext"];
- [defaultContext setParentContext:rootSavingContext];
-
[self MR_setDefaultContext:defaultContext];
+
+ [defaultContext setParentContext:rootSavingContext];
}
}
@@ -154,13 +161,14 @@ + (NSManagedObjectContext *) MR_contextWithParent:(NSManagedObjectContext *)pare
{
NSManagedObjectContext *context = [self MR_contextWithoutParent];
[context setParentContext:parentContext];
- [context MR_obtainPermanentIDsBeforeSaving];
+// [context MR_obtainPermanentIDsBeforeSaving];
return context;
}
+ (NSManagedObjectContext *) MR_newMainQueueContext;
{
NSManagedObjectContext *context = [[self alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
+ MRLog(@"Created Main Queue Context: %@", context);
return context;
}
@@ -182,35 +190,39 @@ + (NSManagedObjectContext *) MR_contextWithStoreCoordinator:(NSPersistentStoreCo
- (void) MR_obtainPermanentIDsBeforeSaving;
{
[[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(contextWillSave:)
+ selector:@selector(MR_contextWillSave:)
name:NSManagedObjectContextWillSaveNotification
object:self];
}
-- (void)contextWillSave:(NSNotification *)notification
+- (void) MR_contextWillSave:(NSNotification *)notification
{
- NSManagedObjectContext *context = (NSManagedObjectContext *)notification.object;
- if (context.insertedObjects.count > 0) {
- NSArray *insertedObjects = [[context insertedObjects] allObjects];
- MRLog(@"Context %@ is about to save. Obtaining permanent IDs for new %lu inserted objects", [context MR_description], (unsigned long)[insertedObjects count]);
+ NSManagedObjectContext *context = [notification object];
+ NSSet *insertedObjects = [context insertedObjects];
+
+ if ([insertedObjects count])
+ {
+ MRLog(@"Context %@ is about to save. Obtaining permanent IDs for new %lu inserted objects", [context MR_workingName], (unsigned long)[insertedObjects count]);
NSError *error = nil;
- BOOL success = [context obtainPermanentIDsForObjects:insertedObjects error:&error];
- if (!success && error) {
+ BOOL success = [context obtainPermanentIDsForObjects:[insertedObjects allObjects] error:&error];
+ if (!success)
+ {
[MagicalRecord handleErrors:error];
}
}
}
-- (void) MR_setContextWorkingName:(NSString *)workingName;
+- (void) MR_setWorkingName:(NSString *)workingName;
{
- [[self userInfo] setObject:workingName forKey:kNSManagedObjectContextWorkingName];
+ [[self userInfo] setObject:workingName forKey:kMagicalRecordNSManagedObjectContextWorkingName];
}
-- (NSString *) MR_contextWorkingName;
+- (NSString *) MR_workingName;
{
- NSString *workingName = [[self userInfo] objectForKey:kNSManagedObjectContextWorkingName];
- if (nil == workingName) {
- workingName = @"UndefinedWorkingContext";
+ NSString *workingName = [[self userInfo] objectForKey:kMagicalRecordNSManagedObjectContextWorkingName];
+ if (nil == workingName)
+ {
+ workingName = @"UNNAMED";
}
return workingName;
}
View
2 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.h
@@ -11,7 +11,7 @@
@interface NSManagedObjectContext (MagicalSaves)
- (void) MR_save;
-- (void) MR_saveErrorHandler:(void (^)(NSError *))errorCallback;
+- (void) MR_saveWithErrorCallback:(void(^)(NSError *))errorCallback;
- (void) MR_saveInBackgroundCompletion:(void (^)(void))completion;
- (void) MR_saveInBackgroundErrorHandler:(void (^)(NSError *))errorCallback;
View
15 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m
@@ -88,20 +88,7 @@ - (void) MR_saveNestedContextsErrorHandler:(void (^)(NSError *))errorCallback co
- (void) MR_save;
{
- [self MR_saveErrorHandler:nil];
-}
-
-- (void) MR_saveErrorHandler:(void (^)(NSError *))errorCallback;
-{
- [self performBlockAndWait:^{
- [self MR_saveWithErrorCallback:errorCallback];
-
- if (self.parentContext) {
- [[self parentContext] performBlockAndWait:^{
- [[self parentContext] MR_saveErrorHandler:errorCallback];
- }];
- }
- }];
+ [self MR_saveWithErrorCallback:nil];
}
- (void) MR_saveInBackgroundCompletion:(void (^)(void))completion;
View
9 MagicalRecord/Categories/NSPersistentStoreCoordinator+MagicalRecord.m
@@ -77,18 +77,21 @@ - (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__
if (!store && [MagicalRecord shouldDeleteStoreOnModelMismatch])
{
- if ([error.domain isEqualToString:NSCocoaErrorDomain] &&
- [error code] == NSMigrationMissingSourceModelError) {
+ if ([[error domain] isEqualToString:NSCocoaErrorDomain] && [error code] == NSPersistentStoreIncompatibleVersionHashError)
+ {
// Could not open the database, so... kill it!
[[NSFileManager defaultManager] removeItemAtURL:url error:nil];
+
+ MRLog(@"Removed incompatible model version: %@", [url lastPathComponent]);
// Try one more time to create the store
store = [self addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:url
options:options
error:&error];
- if (store) {
+ if (store)
+ {
// If we successfully added a store, remove the error that was initially created
error = nil;
}
View
29 MagicalRecord/Core/MagicalRecord+Actions.m
@@ -8,38 +8,15 @@
#import "CoreData+MagicalRecord.h"
#import "NSManagedObjectContext+MagicalRecord.h"
-static dispatch_queue_t background_action_queue;
-
-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 reset_action_queue(void);
-void reset_action_queue(void)
-{
- if (background_action_queue != NULL)
- {
- MRDispatchQueueRelease(background_action_queue);
- background_action_queue = NULL;
- }
-}
-
@implementation MagicalRecord (Actions)
+ (void) saveInBackgroundUsingContext:(NSManagedObjectContext *)localContext block:(void (^)(NSManagedObjectContext *))block completion:(void(^)(void))completion errorHandler:(void(^)(NSError *))errorHandler;
{
- dispatch_async(action_queue(), ^{
+ [localContext performBlock: ^{
block(localContext);
[localContext MR_saveNestedContextsErrorHandler:errorHandler completion:completion];
- });
+ }];
}
+ (void) saveInBackgroundWithBlock:(void (^)(NSManagedObjectContext *))block completion:(void (^)(void))completion errorHandler:(void (^)(NSError *))errorHandler;
@@ -66,7 +43,7 @@ + (void) saveWithBlock:(void (^)(NSManagedObjectContext *localContext))block com
if ([localContext hasChanges])
{
- [localContext MR_saveErrorHandler:errorHandler];
+ [localContext MR_saveWithErrorCallback:errorHandler];
}
if (completion)
View
15 MagicalRecord/Core/MagicalRecord.m
@@ -20,15 +20,13 @@ + (void) MR_cleanUp;
@end
-void reset_action_queue(void);
@implementation MagicalRecord
+ (void) cleanUp
{
[self cleanUpErrorHanding];
[self cleanUpStack];
- reset_action_queue();
}
+ (void) cleanUpStack;
@@ -42,12 +40,13 @@ + (void) cleanUpStack;
+ (NSString *) currentStack
{
NSMutableString *status = [NSMutableString stringWithString:@"Current Default Core Data Stack: ---- \n"];
-
- [status appendFormat:@"Context: %@\n", [NSManagedObjectContext MR_defaultContext]];
- [status appendFormat:@"Model: %@\n", [[NSManagedObjectModel MR_defaultManagedObjectModel] entityVersionHashesByName]];
- [status appendFormat:@"Coordinator: %@\n", [NSPersistentStoreCoordinator MR_defaultStoreCoordinator]];
- [status appendFormat:@"Store: %@\n", [NSPersistentStore MR_defaultPersistentStore]];
-
+
+ [status appendFormat:@"Model: %@\n", [[NSManagedObjectModel MR_defaultManagedObjectModel] entityVersionHashesByName]];
+ [status appendFormat:@"Coordinator: %@\n", [NSPersistentStoreCoordinator MR_defaultStoreCoordinator]];
+ [status appendFormat:@"Store: %@\n", [NSPersistentStore MR_defaultPersistentStore]];
+ [status appendFormat:@"Default Context: %@\n", [[NSManagedObjectContext MR_defaultContext] MR_description]];
+ [status appendFormat:@"Context Chain: \n%@\n", [[NSManagedObjectContext MR_defaultContext] MR_parentChain]];
+
return status;
}
View
2 MagicalRecord/Core/MagicalRecordShorthand.h
@@ -57,6 +57,8 @@
+ (NSArray *) findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending;
+ (NSArray *) findByAttribute:(NSString *)attribute withValue:(id)searchValue andOrderBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context;
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
++ (NSFetchedResultsController *) fetchAllWithDelegate:(id<NSFetchedResultsControllerDelegate>)delegate;
++ (NSFetchedResultsController *) fetchAllWithDelegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
+ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id<NSFetchedResultsControllerDelegate>)delegate;
+ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
+ (NSFetchedResultsController *) fetchAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending;

0 comments on commit 8861927

Please sign in to comment.