AssetManager

@objcMembers
@objc(PESDKAssetManager)
open class AssetManager : NSObject

An AssetManager can be used to cache UIImage and CIImage instances and to download and cache image assets.

  • Caches an image for the given identifier.

    Declaration

    Swift

    open func setImage(_ image: UIImage?, forIdentifier identifier: String)

    Parameters

    image

    The image to store in the cache or nil to delete an image from the cache.

    identifier

    The identifier to register this image for.

  • Returns the image for the given identifier from the cache, if available.

    Declaration

    Swift

    open func image(forIdentifier identifier: String) -> UIImage?

    Parameters

    identifier

    The identifier of the image.

    Return Value

    The cached image or nil.

  • Caches a CIImage for the given identifier.

    Declaration

    Swift

    open func setCIImage(_ image: CIImage?, forIdentifier identifier: String)

    Parameters

    image

    The image to store in the cache or nil to delete an image from the cache.

    identifier

    The identifier to register this image for.

  • Returns a CIImage for the given identifier from the cache, if available. If no CIImage for the given identifier is cached, the UIImage cache is checked for an image with the given key. If such an image exists, it is converted to an instance of CIImage and added to the cache. Using this method to receive a CIImage guarantees that the CIImage used for a given identifier always has the same backing buffer, thus not using more memory than necessary.

    Declaration

    Swift

    open func ciImage(forIdentifier identifier: String) -> CIImage?

    Parameters

    identifier

    The identifier of the image.

    Return Value

    The cached image or nil.

  • This is called with false when downloading starts and again called with true when downloading ends.

    Declaration

    Swift

    open var progressClosure: ((Bool) -> Void)?
  • Retrieves multiple images from the cache and decodes them in the background. If the images are not in the cache, it downloads the images, decodes them and stores them in both a disk cache (if the passed url is not a file url) and an in-memory cache.

    Declaration

    Swift

    open func getImages(at urls: [URL], completion: @escaping (([URL: UIImage], [Error]) -> Void))

    Parameters

    urls

    A list of URLs to images.

    completion

    A completion block that is passed a list of images and errors.

  • Retrieves a single image from the cache and decodes the image in the background. If the image is not in the cache, it downloads the image, decodes it and stores it in both a disk cache (if the passed url is not a file url) and an in-memory cache.

    Declaration

    Swift

    open func getImage(at url: URL, completion: @escaping ((UIImage?, Error?) -> Void))

    Parameters

    url

    The URL of the image.

    completion

    A completion block that is passed the image on success or the error on failure.