On May 22, 2009, at 11:40 AM, Rick Mann wrote:


On May 22, 2009, at 09:58:15, Adam Swift wrote:


On May 22, 2009, at 1:45 AM, Rick Mann wrote:

I'm working on a Framework with a Core Data model. When I first built the test app, I couldn't get the Framework to work right, and so I had all the source files (and .xcdatamodel) included in the test app directly. That worked fine.

I've figured out the Framework issues, and moved the model & source code files back to it. The code runs, but I get this error:

5/22/09 01:38:07 FullExample[37912] +entityForName: could not locate an entity named 'OSMNode' in this model.

I put the files all back in the test app project just to double check, and that works. Do I need to do something special in this situation? The test app code instantiates an object in the Framework and calls a method (this works), but otherwise doesn't directly access the model.


It sounds like you aren't adjusting the code that loads the managed object model when you move the resource into your framework.

Thanks for the response Adam. Could you be more specific? What adjustment needs to be made?


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;
}

- adam
_______________________________________________

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