PDA

View Full Version : Cocoa - NSBundle


OneSadCookie
2002.06.02, 10:14 PM
What is


[NSBundle pathForResource:@"Foo"
ofType:@"jpg"
inDirectory:@"Images"]


equivalent to?

I had assumed that it was equivalent to


[[NSBundle mainBundle] pathForResource:@"Foo"
ofType:@"jpg"
inDirectory:@"Images"]


... but it seems it isn't, because the first returns nil for me where the second works fine.

GoodDoug
2002.06.03, 12:35 PM
The first example (the class method) expects the completely qualified directory path, such as you might get from an NSOpenPanel's completion routine. The second example expects the directory path to be a subpath of the Bundle's path.

In your example, there is no absolute drectory called "Images," therefore the class method (which expects a full directory path) isn't finding the path and returning null.

Hope this helps.