SDWebImagePrefetcher

@interface SDWebImagePrefetcher : NSObject

Prefetch some URLs in the cache for future use. Images are downloaded in low priority.

  • The web image manager used by prefetcher to prefetch images.

    Note

    You can specify a standalone manager and downloader with custom configuration suitable for image prefetching. Such as currentDownloadCount or downloadTimeout.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nonnull) SDWebImageManager *manager;

    Swift

    var manager: SDWebImageManager { get }
  • Maximum number of URLs to prefetch at the same time. Defaults to 3.

    Declaration

    Objective-C

    @property (nonatomic) NSUInteger maxConcurrentPrefetchCount;

    Swift

    var maxConcurrentPrefetchCount: UInt { get set }
  • The options for prefetcher. Defaults to SDWebImageLowPriority.

    Declaration

    Objective-C

    @property (nonatomic) SDWebImageOptions options;

    Swift

    var options: SDWebImageOptions { get set }
  • The context for prefetcher. Defaults to nil.

    Declaration

    Objective-C

    @property (copy, nonatomic, nullable) SDWebImageContext *context;

    Swift

    var context: [SDWebImageContextOption : Any]? { get set }
  • Queue options for prefetcher when call the progressBlock, completionBlock and delegate methods. Defaults to Main Queue.

    Note

    The call is asynchronously to avoid blocking target queue.

    Note

    The delegate queue should be set before any prefetching start and may not be changed during prefetching to avoid thread-safe problem.

    Declaration

    Objective-C

    @property (strong, nonatomic, nonnull) dispatch_queue_t delegateQueue;

    Swift

    var delegateQueue: DispatchQueue { get set }
  • The delegate for the prefetcher. Defaults to nil.

    Declaration

    Objective-C

    @property (nonatomic, nullable) id<SDWebImagePrefetcherDelegate> delegate;

    Swift

    weak var delegate: SDWebImagePrefetcherDelegate? { get set }
  • Returns the global shared image prefetcher instance. It use a standalone manager which is different from shared manager.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nonnull, class) SDWebImagePrefetcher *sharedImagePrefetcher;

    Swift

    class var shared: SDWebImagePrefetcher { get }
  • Allows you to instantiate a prefetcher with any arbitrary image manager.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithImageManager:
        (nonnull SDWebImageManager *)manager;

    Swift

    init(imageManager manager: SDWebImageManager)
  • Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching. It based on the image manager so the image may from the cache and network according to the options property. Prefetching is separate to each other, which means the progressBlock and completionBlock you provide is bind to the prefetching for the list of urls. Attention that call this will not cancel previous fetched urls. You should keep the token return by this to cancel or cancel all the prefetch.

    Declaration

    Objective-C

    - (nullable SDWebImagePrefetchToken *)prefetchURLs:
        (nullable NSArray<NSURL *> *)urls;

    Swift

    func prefetchURLs(_ urls: [URL]?) -> SDWebImagePrefetchToken?

    Parameters

    urls

    list of URLs to prefetch

    Return Value

    the token to cancel the current prefetching.

  • Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching. It based on the image manager so the image may from the cache and network according to the options property. Prefetching is separate to each other, which means the progressBlock and completionBlock you provide is bind to the prefetching for the list of urls. Attention that call this will not cancel previous fetched urls. You should keep the token return by this to cancel or cancel all the prefetch.

    Declaration

    Objective-C

    - (nullable SDWebImagePrefetchToken *)
        prefetchURLs:(nullable NSArray<NSURL *> *)urls
            progress:(nullable SDWebImagePrefetcherProgressBlock)progressBlock
           completed:(nullable SDWebImagePrefetcherCompletionBlock)completionBlock;

    Swift

    func prefetchURLs(_ urls: [URL]?, progress progressBlock: SDWebImagePrefetcherProgressBlock?, completed completionBlock: SDWebImagePrefetcherCompletionBlock? = nil) -> SDWebImagePrefetchToken?

    Parameters

    urls

    list of URLs to prefetch

    progressBlock

    block to be called when progress updates; first parameter is the number of completed (successful or not) requests, second parameter is the total number of images originally requested to be prefetched

    completionBlock

    block to be called when the current prefetching is completed first param is the number of completed (successful or not) requests, second parameter is the number of skipped requests

    Return Value

    the token to cancel the current prefetching.

  • Remove and cancel all the prefeching for the prefetcher.

    Declaration

    Objective-C

    - (void)cancelPrefetching;

    Swift

    func cancelPrefetching()