Question

How can I tell if an image is present in the main app bundle based on a string? For example, is there an image called image1.png in the bundle?

Was it helpful?

Solution

NSBundle method:

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

will return nil if no image was found.

i.e.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" ofType@"png"];
if(filePath.length > 0 && filePath != (id)[NSNull null]) {
   UIImage *myImage = [UIImage imageWithContentsOfFile:filePath];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top