Contents

PHCachingImageManager

An object that facilitates retrieving or generating preview thumbnails, optimized for batch preloading large numbers of assets.

Declaration

class PHCachingImageManager

Mentioned in

Overview

For quick performance when you are working with many assets, a caching image manager can prepare asset images in the background in order to eliminate delays when you later request individual images. For example, use a caching image manager when you want to populate a collection view or similar UI with thumbnails of photo or video assets.

Much of the key functionality of the PHCachingImageManager class is defined by its superclass, PHImageManager. For details, see PHImageManager.

To use a caching image manager:

  1. Create a PHCachingImageManager instance. (This step replaces using the shared PHImageManager instance.)

  2. Use PHAsset class methods to fetch the assets you’re interested in.

  3. To prepare images for those assets, call the startCachingImages(for:targetSize:contentMode:options:) method with the target size, content mode, and options you plan to use when later requesting images for each individual asset.

  4. When you need an image for an individual asset, call the requestImage(for:targetSize:contentMode:options:resultHandler:) method, and pass the same parameters you used when preparing that asset.

If the image you request is among those already prepared, the PHCachingImageManager object immediately returns that image. Otherwise, Photos prepares the image on demand and caches it for later use.

Topics

Preparing Images

Setting Cache Policy

See Also

Asset loading