Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Objective-C Image file name/path different behavior betwewen simulator and device

I have an app in which the app bundle contains an image file (I mean that the file is dragged into XCode and appears in "Other Sources"), and I am using code like:

[[NSBundle mainBundle] pathForResource:@"Auto" ofType:@"jpg"]

to get a path to the image.

I found that when running on a device (iPod Touch), the name is case-sensitive, so that if the file is "Auto" and I use "AUTO", the poath returned is "file://(null)". However on the simulator, if I use "AUTO", it works the same as if I use "Auto".

I am thinking that the fact that the simulator has such a clear difference in behavior from the device is a bug. Do the more experienced users out there think that it is, and that I should report it to Apple?

Thanks.

like image 373
Jonathan Starr Avatar asked Dec 15 '10 20:12

Jonathan Starr


2 Answers

The iOS-Filesystem is case-sensitive, whereas the OSX-Filesystem the Simulator uses isn't.

You have to be very careful with this, I've shot myself in the foot with this more than once.

like image 142
jsadfeew Avatar answered Oct 17 '22 18:10

jsadfeew


This has more to do with NS/CFBundle itself than it does with the underlying file-system:

Directly from Bundle Programming Guide: The Bundle Search Pattern:

Important: The bundle interfaces consider case when searching for resource files in the bundle directory. This case-sensitive search occurs even on file systems (such as HFS+) that are not case sensitive when it comes to file names.

You should always, always be assuming case-sensitivity. Well, perhaps a better way to express that is to say, never assume Case-insensitive-while-case-preserving (which is what HFS+ is). In the not-so-distant future, case-sensitive HFS+ could become the default format for Mac OS X. (In general, it would be preferred over the current case-preserving HFS+, but if Apple were to switch it now, there would likely be hundreds of thousands of apps that would break because of developers who made assumptions they shouldn't have. The iPhone is a clear example of the preference for case-sensitive HFS+. With no legacy programs to worry about, the iPhone has always been case-sensitive).

You are editing your code and resource names right now, so take the time to assure they match.

like image 45
NSGod Avatar answered Oct 17 '22 18:10

NSGod