Skip to content
This repository

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.

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
@@ -52,7 +52,7 @@ - (void) MR_mergeChangesFromiCloud:(NSNotification *)notification;
52 52 [self performBlock:^{
53 53
54 54 MRLog(@"Merging changes From iCloud %@context%@",
55   - self == [NSManagedObjectContext MR_defaultContext] ? @"*** DEFAULT *** " : @"",
  55 + [self MR_isDefaultContext] ? @"*** DEFAULT *** " : @"",
56 56 ([NSThread isMainThread] ? @" *** on Main Thread ***" : @""));
57 57
58 58 [self mergeChangesFromContextDidSaveNotification:notification];
@@ -68,7 +68,7 @@ - (void) MR_mergeChangesFromiCloud:(NSNotification *)notification;
68 68 - (void) MR_mergeChangesFromNotification:(NSNotification *)notification;
69 69 {
70 70 MRLog(@"Merging changes to %@context%@",
71   - self == [NSManagedObjectContext MR_defaultContext] ? @"*** DEFAULT *** " : @"",
  71 + [self MR_isDefaultContext] ? @"*** DEFAULT *** " : @"",
72 72 ([NSThread isMainThread] ? @" *** on Main Thread ***" : @""));
73 73
74 74 [self mergeChangesFromContextDidSaveNotification:notification];
1  MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.h
@@ -21,6 +21,7 @@ extern NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification;
21 21 + (void) MR_resetDefaultContext;
22 22 + (NSManagedObjectContext *) MR_rootSavingContext;
23 23 + (NSManagedObjectContext *) MR_defaultContext;
  24 +- (BOOL) MR_isDefaultContext;
24 25
25 26 - (NSString *) MR_description;
26 27 - (NSString *) MR_parentChain;
5 MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalRecord.m
@@ -102,6 +102,11 @@ + (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
102 102 MRLog(@"Set Default Context: %@", defaultManagedObjectContext_);
103 103 }
104 104
  105 +- (BOOL) MR_isDefaultContext
  106 +{
  107 + return self == defaultManagedObjectContext_;
  108 +}
  109 +
105 110 + (NSManagedObjectContext *) MR_rootSavingContext;
106 111 {
107 112 return rootSavingContext;
2  MagicalRecord/Categories/NSManagedObjectContext/NSManagedObjectContext+MagicalSaves.m
@@ -80,7 +80,7 @@ - (void)MR_saveWithOptions:(MRSaveContextOptions)mask completion:(MRSaveCompleti
80 80 }
81 81 } else {
82 82 // If we're the default context, save to disk too (the user expects it to persist)
83   - if (self == [[self class] MR_defaultContext]) {
  83 + if ([self MR_isDefaultContext]) {
84 84 [[[self class] MR_rootSavingContext] MR_saveWithOptions:MRSaveSynchronously completion:completion];
85 85 }
86 86 // If we're saving parent contexts, do so
1  MagicalRecord/Core/MagicalRecordShorthand.h
@@ -156,6 +156,7 @@
156 156 @interface NSManagedObjectModel (MagicalRecordShortHand)
157 157 + (NSManagedObjectModel *) defaultManagedObjectModel;
158 158 + (void) setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel;
  159 +- (BOOL) isDefaultContext;
159 160 + (NSManagedObjectModel *) mergedObjectModelFromMainBundle;
160 161 + (NSManagedObjectModel *) newManagedObjectModelNamed:(NSString *)modelFileName NS_RETURNS_RETAINED;
161 162 + (NSManagedObjectModel *) managedObjectModelNamed:(NSString *)modelFileName;

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.