Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Assertion failure for no default context #422

Closed
wants to merge 2 commits into from

3 participants

Stephan Michels Malek Trabelsi Tony Arnold
Malek Trabelsi

Hi smic, I am running the same exception "Assertion failure" and tried your changes but the exception persist. Is there any other cause? I am using MR 2.1

Tony Arnold
Owner

I don’t think this PR is going to work in it’s current form. I do think MagicalRecord needs to handle NSManagedDocument and UIManagedDocument out of the box, but it’s going to involve a fair number of changes to other parts of the library.

Tony Arnold
Owner

If you haven't already seen it, @casademora has been putting a lot of work into the upcoming MagicalRecord 3.0, which now supports not specifying a default context. I've been using it in an NSDocument-based app (with a store per document) and will be adding my subclass to support this to MR 3 before it is released.

Tony Arnold tonyarnold closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalObserving.m
View
@@ -52,7 +52,7 @@ - (void) MR_mergeChangesFromiCloud:(NSNotification *)notification;
[self performBlock:^{
MRLog(@"Merging changes From iCloud %@context%@",
- self == [NSManagedObjectContext MR_defaultContext] ? @"*** DEFAULT *** " : @"",
+ [self MR_isDefaultContext] ? @"*** DEFAULT *** " : @"",
([NSThread isMainThread] ? @" *** on Main Thread ***" : @""));
[self mergeChangesFromContextDidSaveNotification:notification];
@@ -68,7 +68,7 @@ - (void) MR_mergeChangesFromiCloud:(NSNotification *)notification;
- (void) MR_mergeChangesFromNotification:(NSNotification *)notification;
{
MRLog(@"Merging changes to %@context%@",
- self == [NSManagedObjectContext MR_defaultContext] ? @"*** DEFAULT *** " : @"",
+ [self MR_isDefaultContext] ? @"*** DEFAULT *** " : @"",
([NSThread isMainThread] ? @" *** on Main Thread ***" : @""));
[self mergeChangesFromContextDidSaveNotification:notification];
1  MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.h
View
@@ -21,6 +21,7 @@ extern NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification;
+ (void) MR_resetDefaultContext;
+ (NSManagedObjectContext *) MR_rootSavingContext;
+ (NSManagedObjectContext *) MR_defaultContext;
+- (BOOL) MR_isDefaultContext;
- (NSString *) MR_description;
- (NSString *) MR_parentChain;
5 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.m
View
@@ -102,6 +102,11 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
MRLog(@"Set Default Context: %@", defaultManagedObjectContext_);
}
+- (BOOL) MR_isDefaultContext
+{
+ return self == defaultManagedObjectContext_;
+}
+
+ (NSManagedObjectContext *) MR_rootSavingContext;
{
return rootSavingContext;
2  MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m
View
@@ -80,7 +80,7 @@ - (void)MR_saveWithOptions:(MRSaveContextOptions)mask completion:(MRSaveCompleti
}
} else {
// If we're the default context, save to disk too (the user expects it to persist)
- if (self == [[self class] MR_defaultContext]) {
+ if ([self MR_isDefaultContext]) {
[[[self class] MR_rootSavingContext] MR_saveWithOptions:MRSaveSynchronously completion:completion];
}
// If we're saving parent contexts, do so
1  MagicalRecord/Core/MagicalRecordShorthand.h
View
@@ -156,6 +156,7 @@
@interface NSManagedObjectModel (MagicalRecordShortHand)
+ (NSManagedObjectModel *) defaultManagedObjectModel;
+ (void) setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel;
+- (BOOL) isDefaultContext;
+ (NSManagedObjectModel *) mergedObjectModelFromMainBundle;
+ (NSManagedObjectModel *) newManagedObjectModelNamed:(NSString *)modelFileName NS_RETURNS_RETAINED;
+ (NSManagedObjectModel *) managedObjectModelNamed:(NSString *)modelFileName;
Something went wrong with that request. Please try again.