I am working with the new UIDocument features in iOS 5.0. I have an application that uses several different data models (MOMD files). According to the documentation for UIManagedDocument, you can override - (NSManagedObjectModel *) managedObjectModel to load a specific data model (by default, all found data models loaded together are loaded). Both data models have overlapping model names with different schemas, so in my case this is undesirable.
Corresponding Apple Doc
So, the problem that I encountered in a simple example is that I can override a function, but I can not assign a result to it. It is private, so the subclass cannot access _managedObjectModel; and, this is read-only, therefore self.managedObjectModel cannot be assigned ..
I was looking for a UIManagedDocument example that overrides managedObjectModel, but Apple doesn't seem to provide it.
I can define a new _myManagedObjectModel instance variable and assign it. Then return this to the access method that I override. I am concerned that this may violate some internal implementation of UIManagedDocument, which does not use the managedObjectModel accessor in preference for _managedObjectModel (which is common in Apples implementations ...)
It seems like a direct problem, and I suspect I'm just missing out on something really simple to allow the correct override.
#import "DTNoteDocument.h"
@implementation DTNoteDocument
NSString * const kDataManagerModelName = @"Note";
-(NSManagedObjectModel*)managedObjectModel {
if (_managedObjectModel != nil)
return _managedObjectModel;
NSBundle *bundle = [NSBundle mainBundle];
NSString *modelPath = [bundle pathForResource:kDataManagerModelName ofType:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
return _managedObjectModel;
}
@end
Title:
#import <UIKit/UIKit.h>
@interface DTNoteDocument : UIManagedDocument
@end
source
share