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
ImagePrefetcher
object, 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.defaultDownloader
andImageCache.defaultCache
will 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. TheCallbackDispatchQueue
inoptionsInfo
will be ignored in this method.Declaration
Swift
public convenience init(urls: [URL], options: KingfisherOptionsInfo? = nil, progressBlock: PrefetcherProgressBlock? = nil, completionHandler: PrefetcherCompletionHandler? = nil)
Parameters
urls
The URLs which should be prefetched.
options
A dictionary could control some behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called every time an resource is downloaded, skipped or cancelled.
completionHandler
Called when the whole prefetching process finished.
Return Value
An
ImagePrefetcher
object. -
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
ImagePrefetcher
object, 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.defaultDownloader
andImageCache.defaultCache
will 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. TheCallbackDispatchQueue
inoptionsInfo
will be ignored in this method.Declaration
Swift
public init(resources: [Resource], options: KingfisherOptionsInfo? = nil, progressBlock: PrefetcherProgressBlock? = nil, completionHandler: PrefetcherCompletionHandler? = nil)
Parameters
resources
The resources which should be prefetched. See
Resource
type for more.options
A dictionary could control some behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called every time an resource is downloaded, skipped or cancelled.
completionHandler
Called when the whole prefetching process finished.
Return Value
An
ImagePrefetcher
object. -
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()