On May 22, 2009, at 13:34:33, Adam Swift wrote:

Sure. Since the data model is now part of the framework project, when you build that framework the model should get built along with the other source files and it will be packaged up into your frameworks Resources directory:

        ${BUILDDIR}/MyFramework.framework/Resources/MyModel.mom

Since it sounds like you've already got some code that's successfully loading the model when it's included in your application project, you might want to look at the initialization of the NSPersistentStoreCoordinator to see from where the model is retrieved (search for initWithManagedObjectModel:). You'll probably want to have a method that takes care of locating, loading and returning the model, if that code lives in the framework, you can use the class to lookup the framework bundle (otherwise you'll want to look up the framework bundle by it's identifier [NSBundle bundleWithIdentifier:@"com.mycompany.MyFramework"])

- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel) return managedObjectModel;
        NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
NSURL *modelPath = [NSURL fileURLWithPath:[frameworkBundle pathForResource:@"MyModel" ofType:@"mom"]]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelPath];
    return managedObjectModel;
}

So, I'm still missing some crucial information. Up to now, I've written an import class that reads an XML file and creates Core Data objects. I pass it the NSPersistentStoreCoordinator from my (otherwise generic) NSPersistentDocument subclass. Inside the Importer class, I create a new NSManagedObjectContext and give it the store I got from the Document. Then I go about my business trying to instantiate entities.

I can't figure out how to add the Framework's MOM to the PSC I get from the Document (which really knows nothing about the Framework). I'm thinking I may need to create an NSPersistentDocument subclass in my Framework that my app(s) can subclass, but this doesn't seem to be a very good solution. What if someday I add a second framework and want to incorporate its model?

So perhaps my app needs to get the model(s) from the framework, and merge them into its own model, but I don't even see how to do that; I see no way to add the MOM to the PSC, and it seems lame to have to create my own PSC (which is nicely handled by NSPersistentDocument, and seems non-trivial).

TIA,

--
Rick

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to