views:

926

answers:

3

Hi,

in the current project I have a number of folders, with subfolders, and these contain images: 01.png, 02.png.

Folder1/FolderA/f1.png Folder1/FolderB/F1.png

When I compile the app, I looked inside the the .app and noticed that all the images are placed in the top level, with no sub-folders.

So clearly when trying to load the image this doesn't work:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"f1" ofType:@"png" inDirectory:@"Folder1/FolderA"];

But even more strangely, when loading image "f1", the image actually loads "F1"

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"f1.png"]];

Anyone have ideas on how to get around this problem?

Is there a compile option to create the folders in the app bundle?

TIA.

A: 

First of all the folders you create in Xcode are simply organizational structures without any counterpart on the filesystem level. In other words all folders except for the "Classes" folder gets flatten out at the filesystem level. Therefore, even if you put your image file in the following location within xcode, it would still exist at the top-level in the filesystem: f1/f2/f3/f4/f5/image.png. Thus, in pathForResource method, you should not include the inDirectory argument.

As for the second issue, mac osx doesn't recognize case-sensitive file names. Therefore, f1 and F1 are equivalent to mac osx and will reference the same file. You can easily see this by executing the following 2 commands at a terminal session:

touch f
touch F

you'll notice that only 1 file exists after this: namely f. If you reverse the 2 commands, you still get one file, but it is named F.

ennuikiller
The images are in actual folders in the system, and not just in XCode. But Xcode does not copy over the folders, just the png files.
What seems to be happening is that images of name "f1.png" gets clobbered by image "F1.png".
yep, that true about the case insensitivity alright.
isn't the case sensitivity all to do the with the file system format when initializing the HD? HFS+ case sensitive would be different.
So as far as I can see, there is no way to create a sub-folder in the main bundle, and therefore the only solution is to add a prefix to the files names to make them unique.
problem solved above...
A: 

ennuikiller is right. I think you can organize your images via Finder in subfolder and then refresh the image location in XCode by right clicking your image and selecting "Get Info" option. Then set the new directory.

Cheers.

R31n4ld0_
Sure, but that still doesn't create folders inside the .app when it is built.
+4  A: 

To create the subfolders inside the .app bundle, you should check the option "Create folder references for any added folders" rather than the default "Recursively create groups for any added folders" Now in XCode, your imported folder appears blue rather than yellow. Build and go and you should see folders in your .app file.

Mugunth Kumar
Perfect! The mistake I did was to drag and drop the folder structure into the resources folder instead of doing option-click, selecting "Add->Existing files" and then selecting the radio button "Create folder references for any added folders". Then the folder is blue.
Could you please accept my answer then :)?
Mugunth Kumar