iphoneimagenamed

(iphone) imageNamed when there are multiple files with same name?


as question says, How does imageNamed work when there are multiple files with the given name under the resource directory?

Is there a way to differentiate two different files with same name (but different path)?

Thank you


Solution

  • The folders in any Xcode bundle are "groups". That is, they are not actual directories. The files in those groups are still located in the bundle's root.

    So, having two (or more) files with the same name in the app bundle is impossible.

    See: http://majicjungle.com/blog/?p=123

    The problem with Groups:

    The directory structure is lost when it’s copied to the iphone app, and so inside your app bundle is just a big list of all your resources in the base directory. As a result of this, duplicate filenames become an issue. If any files within your directory structure on disk contain the same filename, the build process silently screws everything up. It appears to be ‘first in wins’, with only one of the resources making it into the app bundle. So it’s no good if you have a bunch of different level packages each containing a different ‘Terrain.png’ file.

    If you maintain your directory structure by creating folder references, this eliminates the problem of duplicate file names. However, retrieving the files is the problem.

    What you can do is use the NSBundle class:

    [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"path/to/file.jpg"]