开发者

Ignoring iOS high-resolution @2x files

I have an app with a large number of images (1000+). I have a database table which contains all the filenames for these images. Images are loaded on demand based on this filename using UIImage* image = [UIImage imageNamed:...]

Due to the large number of images, I would like to programmatically test to ensure all image that are included in the database are in fact present in the project. To achieve this, I'm pulling all filenames from the table, looping over each filename, running the above code, and checking to see if image != nil. This works just fine.

The problem is that I would like to confirm that both normal resolution and high resolution (@2x) images are there. If the high-resolution file is present but the normal-resolution file is not, my code will not detect this.

Is there some way I can achieve this without having the run this process twice, once per resolution type? Can I force the SDK to ignore @2x files?开发者_StackOverflow社区


You should just use NSFileManager. It will probably be much quicker since it won't actually load the contents of the image files. For each fileName, use NSFileManager's fileExistsAtPath method to check for the image. Then, append "@2x" to the base name to check for the 2x image.


I would use NSBundle to locate the files so the UIImage doesn't have to be loaded into memory, you could use something like...

NSBundle *myBundle = [NSBundle mainBundle];
if([myBundle pathForResource:@"MyImage" forType: @"png"] == nil){
    // low res image isn't there
}

if([myBundle pathForResource:@"MyImage@2x" forType: @"png"] == nil){
    // high res image isn't there
}

Should be much faster...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜