iphone best way to store images

前端 未结 2 1549
情歌与酒
情歌与酒 2021-02-06 18:53

I\'m developing an app that needs to cache some images from the web the images are likely to be 100x100

I just need to know which is better:

  1. Store the imag
2条回答
  •  春和景丽
    2021-02-06 19:30

    Storing images in the database is definitely not recommended by Apple, the filesystem is actually really good at locating files (images in this case) on the disk, which makes it the best solution for saving images. These were the exact same words an Apple technology evangelist used in the iPhone Tech Talk World Tour in Paris. If it are only a few images, you might get away with it, but when the number can potentially become quite large, files is the way to go.

    Besides, you can use the lazy loading methods to grab the images of the disk, this will delay loading the image from disk to when it really is needed.

    [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.png"]]
    

    Edit: imageWithContentsOfFile does not load the image at once, thus not locking the thread, neither does it cache the image. The other method imageNamed: does lock the thread and loads the image at once, on the bright side, it does cache the image.

提交回复
热议问题