I recently discovered a pretty big performance issue in my app that was due to an image not being found in [UIImage imagenamed:].
I was wondering if there is a "drop-in" solution to have this kind of 'errors' logged in some way? I started writing an extension to the UIImage class, something like this:
@implementation UIImage (Debug)
#ifdef DEBUG
+ (UIImage*) imageNamed:(NSString*) name{
UIImage* img = [UIImage imageNamed:name];
if(!img){
NSLog(@"Error: referencing non-exiting image: %@", name);
}
return img;
}
#endif
@end
But this causes an endless loop since [UIImage imageNamed:name] of course causes the extension method to be called again...
Any suggestions?
thanks Thomas
imageNamed:
. It caches and never purges every image you load, so if you load a lot of images then you'll burn through memory very quickly. You can poke around here on StackOverflow for alternate caching schemes. – AndrewSimageNamed:
does cache (which is a performance gain in many cases) it also does purge images from memory when the app receives a memory warning. See for example WWDC 2011 Session 318. There was a bug in earlier iOS version that prevented this, but it's long fixed. – DarkDust