ImagePrefetcher
public class ImagePrefetcher : CustomStringConvertible
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. It also works with
some Cocoa prefetching mechanism like table view or collection view prefetchDataSource
, to start image downloading
and caching before they display on screen.
-
Declaration
Swift
public var description: String { get }
-
The maximum concurrent downloads to use when prefetching images. Default is 5.
Declaration
Swift
public var maxConcurrentDownloads: Int
-
Creates 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 callstart()
on it to begin the prefetching process. The images which are 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. The.callbackQueue
value 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
Options 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.
-
Creates an image prefetcher with an array of resources.
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. The.callbackQueue
value inoptionsInfo
will be ignored in this method.Declaration
Swift
public convenience 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
Options 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.
-
Creates an image prefetcher with an array of sources.
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. The.callbackQueue
value inoptionsInfo
will be ignored in this method.Declaration
Swift
public convenience init(sources: [Source], options: KingfisherOptionsInfo? = nil, progressBlock: PrefetcherSourceProgressBlock? = nil, completionHandler: PrefetcherSourceCompletionHandler? = nil)
Parameters
sources
The sources which should be prefetched. See
Source
type for more.options
Options could control some behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called every time an source fetching successes, fails, is skipped.
completionHandler
Called when the whole prefetching process finished.
-
Starts 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()
-
Stops current downloading progress, and cancel any future prefetching activity that might be occuring.
Declaration
Swift
public func stop()