Kingfisher Documentation

Structure Default​Cache​Serializer

public struct DefaultCacheSerializer: CacheSerializer  

Represents a basic and default CacheSerializer used in Kingfisher disk cache system. It could serialize and deserialize images in PNG, JPEG and GIF format. For image other than these formats, a normalized pngRepresentation will be used.

%127 DefaultCacheSerializer DefaultCacheSerializer CacheSerializer CacheSerializer DefaultCacheSerializer->CacheSerializer

Conforms To

CacheSerializer

An CacheSerializer is used to convert some data to an image object after retrieving it from disk storage, and vice versa, to convert an image to data object for storing to the disk storage.

Initializers

init()

public init()  

Creates a cache serializer that serialize and deserialize images in PNG, JPEG and GIF format.

Properties

`default`

public static let `default`  

The default general cache serializer used across Kingfisher's cache.

compression​Quality

public var compressionQuality: CGFloat = 1.0

The compression quality when converting image to a lossy format data. Default is 1.0.

prefer​Cache​Original​Data

public var preferCacheOriginalData: Bool = false

Whether the original data should be preferred when serializing the image. If true, the input original data will be checked first and used unless the data is nil. In that case, the serialization will fall back to creating data from image.

Methods

data(with:​original:​)

public func data(with image: KFCrossPlatformImage, original: Data?) -> Data?  
  • Parameters:

    • image: The image needed to be serialized.
    • original: The original data which is just downloaded. If the image is retrieved from cache instead of downloaded, it will be nil.
  • Returns: The data object for storing to disk, or nil when no valid data could be serialized.

  • Note: Only when original contains valid PNG, JPEG and GIF format data, the image will be converted to the corresponding data type. Otherwise, if the original is provided but it is not If original is nil, the input image will be encoded as PNG data.

image(with:​options:​)

public func image(with data: Data, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage?  

Gets an image deserialized from provided data.

Parameters

data Data

The data from which an image should be deserialized.

options Kingfisher​Parsed​Options​Info

Options for deserialization.

Returns

An image deserialized or nil when no valid image could be deserialized.