RE: newbie coredata NSManagedObjectModel empty
RE: newbie coredata NSManagedObjectModel empty
- Subject: RE: newbie coredata NSManagedObjectModel empty
- From: Jonathan Saggau <email@hidden>
- Date: Fri, 14 Oct 2005 01:02:58 -0400
>From Matthew Firlik at apple (who mentioned in a subsequent email that
he meant to publish this to the list)
On Oct 12, 2005, at 5:31 PM, Jonathan Saggau wrote:
When I print out the representation of the NSManagedObjectModel it is always
the same:
(NSManagedObjectModel) isEditable 0, entities {}, fetch request templates {}
>From the log it is clear you have a model with no entities in it ...
which means the API (mergedModelFromBundles:) is not finding any
models to merge together. You can validate this further by putting in
this simple code in your application initialization code:
= = = = =
// print out all of the models
NSLog( @"Models in bundle '%@': %@",
[[NSBundle mainBundle] resourcePath],
[[NSBundle mainBundle] pathsForResourcesOfType:@"mom"
inDirectory:nil] );
}
= = = = =
This is what Core Data is doing "under the hood": we look for all
files with the ".mom" extension in the bundles and merge them in. I'm
guessing this code will also return an empty array when you run it,
which means Core Data can't find any models to merge in. If that is
the case, here's what I'd try to debug it:
= = = = =
Ensure the model is included in your target
If the model isn't included in the target, it won't be processed (and
thus not installed, and then not found.) In the "Groups and Files"
view of Xcode, find the target the model is supposed to be in, and
expand it. Then expand the "Compile Sources" phase. Your model
should be listed there. If it isn't, drag the model icon from it's
main location in the "Groups and Files" view to that phase, to add it.
Ensure the model is being compiled
If the model is in the target and the rule is set up correctly, you
should be able to see it being processed in the build log. Clean and
rebuild your project, and then consult the Xcode "Build Results" log.
There should be an entry in the build steps for "Compiling
<YOUR_MODEL_NAME>.xcdatamodel]" If there isn't an entry, then it
might be you are missing a build rules for the models ...
Ensure you have a build rule
Xcode processes model files like sources: we validate it and compile
it down into a runtime format. This is done with a special model
compiler, which Xcode normally associates with that file type.
Double-click on your target icon, and from the inspector that comes up
select the "Rules" tab. Ensure there is a "Data Model Compiler" rule,
and that it is set up to process "Data model files" using the "Data
Model Compiler." If it isn't listed, use the plus button at the
bottom of the window to add one.
Ensure the runtime model is in the right place
The Core Data code expects two things from the runtime models -- that
they end in ".mom" (which is done by the model compiler) and they are
stored in the "Resources" of the deployed bundle. If everything looks
correct from Xcode, then find your built product, show the package
contents, and look in the "Resources" folder. You should find a file
called <YOUR_MODEL_NAME>.mom there. If not, then that's bug-worthy as
well.
Load the model manually
If you DO find an installed model, then it may be something is wrong
with it (causing it not to be loaded.) Instead of using the
mergedModelFromBundles: method, you can also load models directly via
a URL:
NSManagedObjectModel *model = [[NSManagedObjectModel alloc]
initWithContentsOfURL:
[NSURL fileURLWithPath:@"/path/to/your/model.mom"]];
So you can try this if you find the model manually, to see if you can
load it that way as well.
= = = = =
Hope that helps.
- matthew
--
The extent to which an individual can resist being blindly led by
tradition is a good measure of his vitality. - Harry Partch
There is a computer disease that anybody who works with computers
knows about. It's a very serious disease and it interferes completely
with the work. The trouble with computers is that you 'play' with
them! - Richard P. Feynman
Few people are capable of expressing with equanimity opinions which
differ from the prejudices of their social environment. Most people
are not even capable of forming such opinions. - Einstein
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden