需要澄清:我写了这个类方法来加载图像。如果图像不存在,是返回nil
处理返回值的方式还是返回未初始化的UIImage
(仍然为零但更清晰)更清晰?
+ (UIImage*)loadImageByName:(NSString*)name
{
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *imagePath = [documentsPath stringByAppendingPathComponent:name];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagePath];
if (fileExists){
UIImage* tmpImage = [UIImage imageWithContentsOfFile:imagePath];
return tmpImage;
}
return nil;
}