Class

PHCachingImageManager

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

Declaration

class PHCachingImageManager : PHImageManager

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

func stopCachingImagesForAllAssets()

Cancels all image preparation that is currently in progress.

Setting Cache Policy

var allowsCachingHighQualityImages: Bool

A Boolean value that determines whether the image manager prepares high-quality images.

Relationships

Inherits From

Conforms To

See Also

Asset Loading

Loading and Caching Assets and Thumbnails

Request image, video, or Live Photos content, and cache for quick reuse.

class PHImageManager

An object that facilitates retrieving or generating preview thumbnails and asset data.

class PHImageRequestOptions

A set of options affecting the delivery of still image representations of Photos assets you request from an image manager.

class PHVideoRequestOptions

A set of options affecting the delivery of video asset data that you request from an image manager.

class PHLivePhotoRequestOptions

A set of options affecting the delivery of Live Photo assets you request from an image manager.