views:

24

answers:

2

Hi all! I have this problem... I need to load an image from the resources of my app that is called for example mystuff01.jpg but maybe be called mystuff01.gif or png, now, what's the best solution to do this? In my mind there's a cycle to retrieve if the file exists and if exists load it... there's a better solution? thanks

+1  A: 

I think one of the solutions is to create an NSArray {@".jpg", @".png" }, loop through the array and add the extension to the file name, then check if the file name + extension exists, then you load it. It will be easier to do, and can be done with loop

vodkhang
yes, this is what I think.. I'll try
ghiboz
+1  A: 

From UIImage

On iOS 4 and later, the name of the file is not required to specify the filename extension. Prior to iOS 4, you must specify the filename extension.

Otherwise, you would have to try each extension. You could pass the name with each extension directly to [UIImage imageNamed:], find one that works with [mainBundle pathForResource:ofType:];, or use NSFileManager to get a list of resources and look for the closest match.

drawnonward