Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pathForResource? without using extension (Iphone)

Here is what I'm doing, when I create an image with the path in the bundle:


UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"]];

What I want to do is trying to find the path for my image but without using the extension, without using 'ofType' (because the name of my image and her extension is store in my database) something like that:


UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.jpg"]];

But I don't know how to do it.

Best regards,

like image 213
ludo Avatar asked Dec 31 '09 08:12

ludo


1 Answers

Why don't you split the string that you get from the DB?

NSString* fullFileName = @"image.jpg";
NSString* fileName = [[fullFileName lastPathComponent] stringByDeletingPathExtension];
NSString* extension = [fullFileName pathExtension];

Now you can simply use:

[[NSBundle mainBundle] pathForResource:fileName ofType:extension]];
like image 196
Thomas Zoechling Avatar answered Oct 07 '22 16:10

Thomas Zoechling