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
You cannot have two files with the same name in the same folder. You would either have to add a random string to the end of each file like you suggest or save each user's files in a directory allocated to their account.
A filename (or file name) is used to identify a storage location in the file system. OS wants unique file names because when you will tell OS to do something, and you have two files with exactly the same name, OS can't know which file to perform the action on.
Touch and hold the file or folder, then choose an option: Copy, Duplicate, Move, Delete, Rename, or Compress. To modify multiple files or folders at the same time, tap Select, tap your selections, then tap an option at the bottom of the screen.
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With