Search code examples
iossdwebimage

How to use options property with SDWebImagePrefetch?


This might be simple question to some, but I'm having trouble figuring out how to apply options property for SDWebImagePrefetcher

Thus far I set it up to fetch some urls with completion block

SDWebImagePrefetcher.shared.prefetchURLs(
        urls as [URL],
        progress: nil,
        completed: { finished, skipped in
          print("Finished")
        }
      )

I think options are set up like this? But I am not sure what needs to come instead of /* ? */ in order to enable one of the options SDWebImageCacheMemoryOnly

SDWebImagePrefetcher.shared.options = /* ? */

Solution

  • options is of type SDWebImageOptions, which is declared using the NS_OPTIONS macro. This means you can combine options using the bitwise or operator in Objective-C:

    SDWebImagePrefetcher.shared.options = SDWebImageRetryFailed | SDWebImageLowPriority; // etc
    

    Or like this in Swift:

    SDWebImagePrefetcher.shared.options = [.retryFailed, .lowPriority] // etc
    

    All the options can be found here: https://sdwebimage.github.io/Enums/SDWebImageOptions.html