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:07:24 -0400
More interesting info from Matthew on how to load NSManagedObjectModels::
On Oct 13, 2005, at 3:13 PM, Jonathan Saggau wrote:
> AHA! Thanks Matthew!
>
> Here's what's happened:
> I'm using the /Developer/Tools/otest executable as the target for
> my test bundle testCases.octest, so the resourcepath was /Developer/
> Tools. The .mom file is in the bundle!
(Matthew)
Ah ... I didn't realize you were using a testing tool. Yes, the
[NSBundle mainBundle] API will return the bundle for the executable,
which is why it returned "/Developer/Tools/".
> 2. Is there a smarter target to use besides /Developer/Tools/otest
> (or should I put the otest executable in the testCases.octest or
> something)? I would rather not hard-code the
> initWithContentsOfURL: path for portability sake. (I have a buddy
> who wants to play with this tool I'm working on).
I would agree, hard-coding the URL to the model is less-than-ideal.
However, there is some degree of 'static definition' that must exist
between your test cases and the product being tested. Rather, since
your tests are testing a specific collection of functionality (for
example, the code in something like "BusinessLogic.framework"), you
may be able to use that bit of information with a little glue code to
make it work.
In fact ... you may have, already. It strikes me that you are trying
to test content which is in a bundle -- but is the model the only
thing in the bundle? Is there no source code either? You'd have to
have the bundle loaded in at some point, if you have source code,
otherwise it won't be able to execute. If you've already linked in
the framework or loaded your bundle into your project, you should be
passing in something OTHER than "mainBundle" for the managed object
model API, since we KNOW the model isn't there. For example:
NSManagedObjectModel *model = [NSManagedObjectModel
mergedModelFromBundles:
[NSBundle allBundles]]
would load the models from all of the NON-FRAMEWORK bundles. (You'd
want to use this if your application was using a series of plugins or
the like.) You can also do:
NSManagedObjectModel *model = [NSManagedObjectModel
mergedModelFromBundles:
[NSBundle allFrameworks]]
and create a model from all of the framework bundles. You could even
be much more specific, ala:
NSBundle *myBundle = [NSBundle bundleWithIdentifier:
@"my.bundle.identifier"];
NSManagedObjectModel *model = [NSManagedObjectModel
mergedModelFromBundles:
[NSArray arrayWithObject: myBundle]];
to load JUST the models from JUST your bundle. (Note the identifier
you use is the CFBundleIdentifier, not the name of the bundle
itself. You can set the bundle identifier by using the "Properties"
tab of the inspector for your bundle's target, in Xcode.) But of
course, these are only ways to get models from bundle you already
have LOADED, which may not be your case.
However, loading bundles manually is rather easy. You can imagine a
setup where you have your test setup use a command-line variable or
user default to define the bundles it should automatically load on
startup.
_______________________________________________
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