Protocols

The following protocols are available globally.

  • This is the protocol for SDAnimatedImage class only but not for SDAnimatedImageCoder. If you want to provide a custom animated image class with full advanced function, you can conform to this instead of the base protocol.

    See more

    Declaration

    Objective-C

    @protocol SDAnimatedImage <SDAnimatedImageProvider>

    Swift

    protocol SDAnimatedImageProtocol : SDAnimatedImageProvider
  • A protocol to allow custom disk cache used in SDImageCache.

    See more

    Declaration

    Objective-C

    @protocol SDDiskCache <NSObject>

    Swift

    protocol SDDiskCacheProtocol : NSObjectProtocol
  • This is the image cache protocol to provide custom image cache for SDWebImageManager. Though the best practice to custom image cache, is to write your own class which conform SDMemoryCache or SDDiskCache protocol for SDImageCache class (See more on SDImageCacheConfig.memoryCacheClass & SDImageCacheConfig.diskCacheClass). However, if your own cache implementation contains more advanced feature beyond SDImageCache itself, you can consider to provide this instead. For example, you can even use a cache manager like SDImageCachesManager to register multiple caches.

    See more

    Declaration

    Objective-C

    @protocol SDImageCache <NSObject>

    Swift

    protocol SDImageCache : NSObjectProtocol

Coder

  • This is the image coder protocol to provide custom image decoding/encoding. These methods are all required to implement.

    Note

    Pay attention that these methods are not called from main queue.
    See more

    Declaration

    Objective-C

    @protocol SDImageCoder <NSObject>

    Swift

    protocol SDImageCoder : NSObjectProtocol

Progressive Coder

  • This is the image coder protocol to provide custom progressive image decoding. These methods are all required to implement.

    Note

    Pay attention that these methods are not called from main queue.
    See more

    Declaration

    Objective-C

    @protocol SDProgressiveImageCoder <SDImageCoder>

    Swift

    protocol SDProgressiveImageCoder : SDImageCoder

Animated Image Provider

Animated Coder

SDImageLoader

  • This is the protocol to specify custom image load process. You can create your own class to conform this protocol and use as a image loader to load image from network or any available remote resources defined by yourself. If you want to implement custom loader for image download from network or local file, you just need to concentrate on image data download only. After the download finish, call SDImageLoaderDecodeImageData or SDImageLoaderDecodeProgressiveImageData to use the built-in decoding process and produce image (Remember to call in the global queue). And finally callback the completion block. If you directly get the image instance using some third-party SDKs, such as image directly from Photos framework. You can process the image data and image instance by yourself without that built-in decoding process. And finally callback the completion block.

    Note

    It’s your responsibility to load the image in the desired global queue(to avoid block main queue). We do not dispatch these method call in a global queue but just from the call queue (For SDWebImageManager, it typically call from the main queue).
    See more

    Declaration

    Objective-C

    @protocol SDImageLoader <NSObject>

    Swift

    protocol SDImageLoader : NSObjectProtocol
  • A transformer protocol to transform the image load from cache or from download. You can provide transformer to cache and manager (Through the transformer property or context option SDWebImageContextImageTransformer).

    Note

    The transform process is called from a global queue in order to not to block the main queue.
    See more

    Declaration

    Objective-C

    @protocol SDImageTransformer <NSObject>

    Swift

    protocol SDImageTransformer : NSObjectProtocol
  • A protocol to allow custom memory cache used in SDImageCache.

    See more

    Declaration

    Objective-C

    @protocol SDMemoryCache <NSObject>

    Swift

    protocol SDMemoryCacheProtocol : NSObjectProtocol
  • This is the protocol for cache key filter. We can use a block to specify the cache key filter. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using @convention(block) to store a block into context options.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageCacheKeyFilter <NSObject>

    Swift

    protocol SDWebImageCacheKeyFilterProtocol : NSObjectProtocol
  • This is the protocol for cache serializer. We can use a block to specify the cache serializer. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using @convention(block) to store a block into context options.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageCacheSerializer <NSObject>

    Swift

    protocol SDWebImageCacheSerializerProtocol : NSObjectProtocol
  • This is the protocol for downloader decryptor. Which decrypt the original encrypted data before decoding. Note progressive decoding is not compatible for decryptor. We can use a block to specify the downloader decryptor. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using @convention(block) to store a block into context options.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageDownloaderDecryptor <NSObject>

    Swift

    protocol SDWebImageDownloaderDecryptorProtocol : NSObjectProtocol
  • Describes a downloader operation. If one wants to use a custom downloader op, it needs to inherit from NSOperation and conform to this protocol For the description about these methods, see SDWebImageDownloaderOperation

    Note

    If your custom operation class does not use NSURLSession at all, do not implement the optional methods and session delegate methods.
    See more

    Declaration

    Objective-C

    @protocol SDWebImageDownloaderOperation <NSURLSessionTaskDelegate,
                                             NSURLSessionDataDelegate>

    Swift

    protocol SDWebImageDownloaderOperationProtocol : URLSessionDataDelegate
  • This is the protocol for downloader request modifier. We can use a block to specify the downloader request modifier. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using @convention(block) to store a block into context options.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageDownloaderRequestModifier <NSObject>

    Swift

    protocol SDWebImageDownloaderRequestModifierProtocol : NSObjectProtocol
  • This is the protocol for downloader response modifier. We can use a block to specify the downloader response modifier. But Using protocol can make this extensible, and allow Swift user to use it easily instead of using @convention(block) to store a block into context options.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageDownloaderResponseModifier <NSObject>

    Swift

    protocol SDWebImageDownloaderResponseModifierProtocol : NSObjectProtocol
  • A protocol to custom the indicator during the image loading. All of these methods are called from main queue.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageIndicator <NSObject>

    Swift

    protocol SDWebImageIndicator : NSObjectProtocol
  • The manager delegate protocol.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageManagerDelegate <NSObject>

    Swift

    protocol SDWebImageManagerDelegate : NSObjectProtocol
  • A protocol represents cancelable operation.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageOperation <NSObject>

    Swift

    protocol SDWebImageOperation : NSObjectProtocol
  • This is the protocol for options processor. Options processor can be used, to control the final result for individual image request’s SDWebImageOptions and SDWebImageContext Implements the protocol to have a global control for each indivadual image request’s option.

    See more

    Declaration

    Objective-C

    @protocol SDWebImageOptionsProcessor <NSObject>

    Swift

    protocol SDWebImageOptionsProcessorProtocol : NSObjectProtocol
  • The prefetcher delegate protocol

    See more

    Declaration

    Objective-C

    @protocol SDWebImagePrefetcherDelegate <NSObject>

    Swift

    protocol SDWebImagePrefetcherDelegate : NSObjectProtocol