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.
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?
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.