Nuke Documentation

Class Image​Prefetcher

public final class ImagePrefetcher  

Prefetches and caches images to eliminate delays when requesting the same images later.

The prefetcher cancels all of the outstanding tasks when deallocated.

All ImagePrefetcher methods are thread-safe and are optimized to be used even from the main thread during scrolling.

Nested Types

ImagePrefetcher.Destination

Prefetching destination.

Initializers

init(pipeline:​destination:​max​Concurrent​Request​Count:​)

public init(pipeline: ImagePipeline = ImagePipeline.shared,
                destination: Destination = .memoryCache,
                maxConcurrentRequestCount: Int = 2)  

Initializes the ImagePrefetcher instance.

  • parameter maxConcurrentRequestCount: 2 by default.

Parameters

manager

Loader.shared by default.

destination Destination

.memoryCache by default.

Properties

is​Paused

public var isPaused: Bool = false  

Pauses the prefetching.

priority

public var priority: ImageRequest.Priority = .low  

The priority of the requests. By default, .low.

Changing the priority also changes the priority of all of the outstanding tasks managed by the prefetcher.

Methods

start​Prefetching(with:​)

public func startPrefetching(with requests: [ImageRequestConvertible])  

Starts prefetching images for the given requests.

When you need to display the same image later, use the ImagePipeline or the view extensions to load it as usual. The pipeline will take care of coalescing the requests to avoid any duplicate work.

The priority of the requests is set to the priority of the prefetcher (.low by default).

stop​Prefetching(with:​)

public func stopPrefetching(with requests: [ImageRequestConvertible])  

Stops prefetching images for the given requests and cancels outstanding requests.

You don't need to balance the number of start and stop requests. If you have multiple screens with prefetching, create multiple instances of ImagePrefetcher.

Parameters

destination

.memoryCache by default.

stop​Prefetching()

public func stopPrefetching()  

Stops all prefetching tasks.