Re: Bundle problems
Re: Bundle problems
- Subject: Re: Bundle problems
- From: Greg Titus <email@hidden>
- Date: Fri, 8 Jun 2001 22:04:27 -0700
On Friday, June 8, 2001, at 05:42 PM, Michael P. Rogers wrote:
>
I am trying to follow the rules and load images from a bundle, as
>
opposed to a separate directory. Unfortunately, I keep getting nil
>
back from
>
>
imageFiles = [NSBundle pathsForResourcesOfType:@"jpg"
>
inDirectory:@"Images"];
[...]
>
Any suggestions would be appreciated.
The problem you are having here is that you are using a class method
from NSBundle instead of an instance method. It is especially confusing
because Apple has a documentation error so both the class method and
instance method with this name have identical descriptions even though
they are different. (The instance method documentation is correct and
the class method documentation is wrong.)
In the class method case (as in your example) you actually need to pass
in a fully-qualified path for the directory to look in, and nil is an
error (as you discovered).
What you want is to look in a directory inside your particular bundle,
which means you want to call the instance method on the bundle which you
want to look inside of - which in this case is the main application
bundle for your app. So this code:
imageFiles = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg"
inDirectory:@"Images"];
... should do what you were expecting the class method to do.
Hope this helps,
--Greg