views:

70

answers:

1

Hi,

I'd like to know if it is possible to store resources data into "sub-bundles" or "sub-packages" that I could put into my main AppBundle.

Indeed, I'd like to create a kind of player that reads "content packages", which are all organized the same way, with a standard hierarchical organization :

Package1:
- index.txt
- credits.txt
- Pictures/
-- Pic1.png
-- Pic2.png
- Movies/
-- intro.mov
-- outro.mov

My problem is that I can't find any way to make benefit of a hierarchical organisation into my Application package - I mean that I don't know how to distinguish "Folder1/index.txt" from "Folder2/index.txt", because I just use the "index.txt" identifier when I try to load the content of the file ...

I hope someone could help me, by the way I apologize for my poor english,

Cheers,

+1  A: 

First, make sure that you're copying the files into subdirectories of Resources. One way to do this is to add your Package1 as a "folder reference" (select "Create Folder References" instead of "Recursively create groups" when you add it to the project). Another way to do it is to create a new Copy Files build action that copies the files into a subdirectory of Resources.

Once you've done that, you can use NSBundle's -pathForResource:ofType:inDirectory: to find the particular file you want. There's no need to go to the trouble of creating a sub-bundle (which is possible, but more complex).

Rob Napier
does this really work? I thought I'd found that if I have an image in a subdirectory in my project, it's still added to the "root directory" of the application bundle.
David Maymudes
Yes, I use this myself. The question isn't whether you have a subdirectory in the project; it's what you put in the Copy Files rule. If you put a directory reference in there, it'll create the directory and populate it. Otherwise you can create a new Copy Files rule that puts things in another directory. But you can't just put things in subdirectories in the project; that's not relevant to the Copy Files stage.
Rob Napier