Search code examples
iosxcodensbundle

How to add a directory structure with duplicate filenames to a project?


I have a directory that boils down to this:

/ 
 - character0 -- attribute0 -- image.png
 - character1 -- attribute0 -- image.png 

I dropped it in XCode, in order to define two characters. Now I would like to load each image.png

CIImage * cheetah = [CIImage imageWithContentsOfURL:[[NSBundle mainBundle] 
                     URLForResource:@"image" withExtension:@".png"]];

What is cheetah ? How can I get character0 ?


Solution

  • If you just add two files "image.png" to your project, both will be copied to the top-level directory of the application bundle, so that you end with only one file "image.png" in the app.

    If you drag the folders "character0", "character1" onto your project and choose the option "Create folder references for any added folders", then the entire folder hierarchies will be copied to the application bundle, and you can reference the resources separately with e.g.

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"image"
                                         withExtension:@"png" 
                                          subdirectory:@"character0/attribute0"];