An object that facilitates retrieving or generating preview thumbnails, optimized for batch preloading large numbers of assets.
- iOS 8+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 10+
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
PHCaching class is defined by its superclass,
PHImage. For details, see
To use a caching image manager:
PHCachinginstance. (This step replaces using the shared
PHAssetclass methods to fetch the assets you’re interested in.
To prepare images for those assets, call the
startmethod with the target size, content mode, and options you plan to use when later requesting images for each individual asset.
Caching Images(for: target Size: content Mode: options:)
When you need an image for an individual asset, call the
requestmethod, and pass the same parameters you used when preparing that asset.
Image(for: target Size: content Mode: options: result Handler:)
If the image you request is among those already prepared, the
PHCachingobject immediately returns that image. Otherwise, Photos prepares the image on demand and caches it for later use.