我最近在我的应用程序中发现了一个相当大的性能问题,这是由于在[UIImage imagenamed:]中找不到图像.
我想知道是否有"插入式"解决方案以某种方式记录这种"错误"?我开始编写UIImage类的扩展,如下所示:
@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
Run Code Online (Sandbox Code Playgroud)
但这导致无限循环,因为[UIImage imageNamed:name]当然会导致再次调用扩展方法...
有什么建议?
谢谢托马斯