Kingfisher Documentation

Protocol Cache​Serializer

public protocol 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.

%19 CacheSerializer CacheSerializer DefaultCacheSerializer DefaultCacheSerializer DefaultCacheSerializer->CacheSerializer FormatIndicatedCacheSerializer FormatIndicatedCacheSerializer FormatIndicatedCacheSerializer->CacheSerializer

Types Conforming to Cache​Serializer

DefaultCacheSerializer

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.

FormatIndicatedCacheSerializer

FormatIndicatedCacheSerializer lets you indicate an image format for serialized caches.

Requirements

data(with:​original:​)

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

Gets the serialized data from a provided image and optional original data for caching to disk.

Parameters

image KFCross​Platform​Image

The image needed to be serialized.

original Data?

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.

image(with:​options:​)

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

Gets an image from provided serialized data.

Parameters

data Data

The data from which an image should be deserialized.

options Kingfisher​Parsed​Options​Info

The parsed options for deserialization.

Returns

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