ImagePrefetcher
public class ImagePrefetcher
ImagePrefetcher represents a downloading manager for requesting many images via URLs, then caching them.
This is useful when you know a list of image resources and want to download them before showing.
-
The maximum concurrent downloads to use when prefetching images. Default is 5.
Declaration
Swift
public var maxConcurrentDownloads = 5 -
Init an image prefetcher with an array of URLs.
The prefetcher should be initiated with a list of prefetching targets. The URLs list is immutable. After you get a valid
ImagePrefetcherobject, you could callstart()on it to begin the prefetching process. The images already cached will be skipped without downloading again.Note
By default, the
ImageDownloader.defaultDownloaderandImageCache.defaultCachewill be used as the downloader and cache target respectively. You can specify another downloader or cache by using a customizedKingfisherOptionsInfo. Both the progress and completion block will be invoked in main thread. TheCallbackDispatchQueueinoptionsInfowill be ignored in this method.Declaration
Swift
public convenience init(urls: [URL], options: KingfisherOptionsInfo? = nil, progressBlock: PrefetcherProgressBlock? = nil, completionHandler: PrefetcherCompletionHandler? = nil)Parameters
urlsThe URLs which should be prefetched.
optionsA dictionary could control some behaviors. See
KingfisherOptionsInfofor more.progressBlockCalled every time an resource is downloaded, skipped or cancelled.
completionHandlerCalled when the whole prefetching process finished.
Return Value
An
ImagePrefetcherobject. -
Init an image prefetcher with an array of resources.
The prefetcher should be initiated with a list of prefetching targets. The resources list is immutable. After you get a valid
ImagePrefetcherobject, you could callstart()on it to begin the prefetching process. The images already cached will be skipped without downloading again.Note
By default, the
ImageDownloader.defaultDownloaderandImageCache.defaultCachewill be used as the downloader and cache target respectively. You can specify another downloader or cache by using a customizedKingfisherOptionsInfo. Both the progress and completion block will be invoked in main thread. TheCallbackDispatchQueueinoptionsInfowill be ignored in this method.Declaration
Swift
public init(resources: [Resource], options: KingfisherOptionsInfo? = nil, progressBlock: PrefetcherProgressBlock? = nil, completionHandler: PrefetcherCompletionHandler? = nil)Parameters
resourcesThe resources which should be prefetched. See
Resourcetype for more.optionsA dictionary could control some behaviors. See
KingfisherOptionsInfofor more.progressBlockCalled every time an resource is downloaded, skipped or cancelled.
completionHandlerCalled when the whole prefetching process finished.
Return Value
An
ImagePrefetcherobject. -
Start to download the resources and cache them. This can be useful for background downloading of assets that are required for later use in an app. This code will not try and update any UI with the results of the process.
Declaration
Swift
public func start() -
Stop current downloading progress, and cancel any future prefetching activity that might be occuring.
Declaration
Swift
public func stop()
View on GitHub
Install in Dash
ImagePrefetcher Class Reference