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


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 lets you indicate an image format for serialized caches.



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

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


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.


The data object for storing to disk, or nil when no valid data could be serialized.


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

Gets an image from provided serialized data.


data Data

The data from which an image should be deserialized.

options Kingfisher​Parsed​Options​Info

The parsed options for deserialization.


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