UIImage imageWithContentsOfFile correct pathForResource

ios, objective-c, uiimage, uiimageview

Solution

If you can't rename the source data (which you should do really), then you would need to use the file manager to get a list of all of the files available and then do a case insensitive filter to get the matching name and use that.

Problem

I have resources: ``` Test.png test1.jpg tesT2.jpg tEst3.jpg ``` I need to show this image in `UIImageView`. So I wrote: ``` imgView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[myObject.filename stringByDeletingPathExtension] ofType:[myObject.filename pathExtension]]]; ``` `myObject` is entity in my model. I get `filename` from xml, but in xml it have format like: ``` filename="test.png" filename="test1.jpg" filename="test3.jpg" filename="test3.jpg" ``` So my Image is `(null)` because in pathForResource I search `@"test" ofType "png"`, but need `@"Test" ofType"png"`. How I can get correct resources without renaming them?

Original source

Related problems