1
votes

I've been looking for a way to search a subdirectory in my main bundle recursively. At first glance the instance method, "– pathForResource:ofType:inDirectory:" defined on NSBundle seems like it would do the job. It specifies that if you pass in 'nil' as the type of resource the method will search all subdirectories for the given resource matching the resource name.

https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html

I've tried it like so:

NSString *pathForResource = [[NSBundle mainBundle] pathForResource:spriteFrameName ofType:nil inDirectory:@"images"];

Unfortunately that does not work. Looking at the documentation it seems that it is also says it returns an array of pathNames even though the return value is stated as being an 'NSString*'.

It points me towards resources for internationalization when talking about recursing the subdirectories which leads me to believe that the recursion might be in regards to related resource language directories but that intent somehow got lost on me.

Am I out to lunch on not getting this to work or might this just be a case of confusing documentation?

1
Why would you not know the path to resources in your own app bundle?deleted_user
We have a build-time tool that randomly organizes the structure of resources in our app. (Our artists have a bit of leeway in how they organize things. I need some basic files to find and validate though that I'm told are guaranteed to exist.)djdrzzy

1 Answers

2
votes

I think you have found a documentation error.

To search your bundle recursively, send resourcePath to the bundle, then pass that to an NSFileManager in an enumeratorAtPath: message.