Created
January 25, 2013 06:55
-
-
Save smic/4632383 to your computer and use it in GitHub Desktop.
Replace the managed object context of a NSPersistentDocument by a context created by MagicalRecord.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
@interface SMDocument : NSPersistentDocument | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SMDocument.h" | |
@implementation SMDocument | |
- (id)init { | |
self = [super init]; | |
if (self) { | |
NSManagedObjectContext *context = self.managedObjectContext; | |
if (context.concurrencyType != NSMainQueueConcurrencyType) { | |
NSUndoManager *undoManager = context.undoManager; | |
NSPersistentStoreCoordinator *coordinator = context.persistentStoreCoordinator; | |
context = [NSManagedObjectContext newMainQueueContext]; | |
context.persistentStoreCoordinator = coordinator; | |
context.undoManager = undoManager; | |
self.managedObjectContext = context; | |
} | |
NSAssert1(self.managedObjectContext.concurrencyType == NSMainQueueConcurrencyType, @"Wrong concurrency type: %li", self.managedObjectContext.concurrencyType); | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! Have you tested this idea? I would never have thought that setting the property
managedObjectContext
onNSDocument
could be authorized (yes, it is said in the doc that you can...)!!!! How did you get this idea?