Permalink
Browse files

Merge branch 'develop' of github.com:magicalpanda/MagicalRecord into …

…develop
  • Loading branch information...
2 parents 3656e74 + c0a1657 commit b5e5716307ac5a1d96a137eff9d56330cdb38657 @blackgold9 blackgold9 committed Nov 1, 2012
@@ -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;
@@ -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
@@ -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
@@ -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;
}
@@ -194,7 +202,7 @@ - (void) MR_contextWillSave:(NSNotification *)notification
if ([insertedObjects count])
{
- MRLog(@"Context %@ is about to save. Obtaining permanent IDs for new %lu inserted objects", [context MR_description], (unsigned long)[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 allObjects] error:&error];
if (!success)
@@ -204,16 +212,17 @@ - (void) MR_contextWillSave:(NSNotification *)notification
}
}
-- (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;
}
@@ -40,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;
}
@@ -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 b5e5716

Please sign in to comment.