-
-
Notifications
You must be signed in to change notification settings - Fork 6k
5.0 Migration guide
SDWebImage 5.0 is the latest major release of SDWebImage, a top library for downloading and caching images. As a major release, following Semantic Versioning conventions, 5.0 introduces several API-breaking changes with its new architecture.
This guide is provided in order to ease the transition of existing applications using SDWebImage 4.X to the latest APIs, as well as explain the design and structure of new and changed functionality.
SDWebImage 5.0 officially supports iOS 8 and later, Mac OS X 10.10 and later, watchOS 2 and later and tvOS 9 and later. It needs Xcode 9 or later to be able to build everything properly.
For targeting previous versions of the SDKs, check README - Backwards compatibility.
Using the view categories brings no change from 4.x to 5.0.
Objective-C:
[imageView sd_setImageWithURL:url placeholderImage:placeholderImage];Swift:
imageView.sd_setImage(with: url, placeholderImage: placeholder)However, all view categories in 5.0 introduce a new extra arg called SDWebImageContext. Which can hold anything that previous enum SDWebImageOptions can not. This allow user to control advanced behavior for image loading as well as many aspect (cache, loader, etc). See the declaration for SDWebImageContext for detailed information.
In 5.0, we introduce a brand new animated image solution. Which including animated image loading, rendering, decoding, and also support customization for advanced user.
This animated image solution is available for iOS/tvOS/macOS. The SDAnimatedImage is subclass of UIImage/NSImage, and SDAnimatedImageView is subclass of UIImageView/NSImageView, to allow most compatible for common framework APIs. See Animated Image for more detailed information.
In 5.0, we introduce a easy way to provide a image transform process after the image was downloaded from network. Which allow user to easily scale, rotate, rounded corner the original image. And even support chain a list of transformers together to output the final one. These transformed image will also stored to cache to avoid duplicate process. See Image Transformer for more detailed information.
In 5.0, we refactor our framework architecture with many aspect. This make our framework easier to customize for advanced user, without hook anything or create their fork. We introduce Custom Cache to control detailed cache loading behavior, and separate the memory cache & disk cache implementation. We introduce Custom Loader to allow custom loading from your own source (which even not need to be on network). And also, we change current Custom Coder to works better for custom image decoder/encoder and animated image.
In 5.0, we refactor the current image loading indicator API. To use a better and extensible API for both iOS/tvOS/macOS. Which is suitable for easy usage for provide a loading view during the image loading process. See View Indicator for more detailed information.
Since we introduce the new animated image solution. Now we are no longer hosting the integration with FLAnimatedImage inside this repo. But for user who need FLAnimatedImage support. We have a dedicated repo for that and contains all the code compatible for SDWebImage 5.0. See SDWebImageFLPlugin for more detailed information.
By taking the advantage of Custom Loader feature, we introduce a plugin to allow easily load Photos Library images. See SDWebImagePhotosPlugin for more detailed information.
- moved
maxMemoryCostandmaxMemoryCountLimittoSDImageCacheConfig -
makeDiskCachePath:removed, useNSSearchPathForDirectoriesInDomainswith NSString's Path API instead. -
addReadOnlyCachePath:removed, useadditionalCachePathBlockinstead -
cachePathForKey:inPath:removed, usecachePathForKey:with NSString's path API instead. -
defaultCachePathForKey:removed, usecachePathForKey:instead -
SDCacheQueryCompletedBlockrenamed toSDImageCacheQueryCompletionBlock -
SDWebImageCheckCacheCompletionBlockrenamed toSDImageCacheCheckCompletionBlock -
SDWebImageCalculateSizeBlockrenamed toSDImageCacheCalculateSizeBlock
-
shouldDecompressImagesremoved. UseSDImageCacheAvoidDecodeImagein cache options instead
-
loadImageWithURL:options:progress:completed:changed thecompletedparam requirement fromnullabletononnull -
loadImageWithURL:options:progress:completed:return typeid<SDWebImageOperation>changed toSDWebImageCombinedOperation * -
imageCachechanged from nullable to nonnull. And property type changed fromSDImageCache *toid<SDImageCache>. The default value does not change. -
imageDownloaderrenamed toimageLoaderand changed from nullable to nonnull. And property type changed fromSDWebImageDownloader *toid<SDImageLoader>. The default value does not change. -
cacheKeyFilterproperty type changed toid<SDWebImageCacheKeyFilter>, you can use+[SDWebImageCacheKeyFilter cacheKeyFilterWithBlock:]to create -
cacheSerializerproperty type changed toid<SDWebImageCacheSerializer>, you can use+[SDWebImageCacheSerializer cacheSerializerWithBlock:]to create -
SDWebImageCacheKeyFilterBlock'surlarg change from nullable to nonnull -
initWithCache:downloader:'scachearg type changed fromSDImageCache *toid<SDImageCache> -
initWithCache:downloaderrenamed toinitWithCache:loader: -
saveImageToCache:forURL:removed. UseSDImageCache storeImage:imageData:forKey:cacheType:completion:(orSDImageCache storeImage:forKey:toDisk:completion:if you use default cache class) withcacheKeyForURL:instead. -
diskImageExistsForURL:completion:removed. UseSDImageCache containsImageForKey:cacheType:completion:(orSDImageCache diskImageExistsWithKey:completion:if you use default cache class) withcacheKeyForURL:instead. -
cachedImageExistsForURL:completionremoved. UseSDImageCache containsImageForKey:cacheType:completion:(orSDImageCache diskImageExistsWithKey:completion:andSDImageCache imageFromMemoryCacheForKey:if you use default cache class) withcacheKeyForURL:instead.
- removed
imageManager:transformDownloadedImage:forKey:, useSDImageTransformerwith context option instead
-
sd_internalSetImageWithURL:placeholderImage:options:operationKey:setImageBlock:progress:completed:renamed toUIView sd_internalSetImageWithURL:placeholderImage:options:context:setImageBlock:progress:completed:(The biggest changes is that the completion block type fromSDExternalCompletionBlocktoSDInternalCompletionBlock. Which allow advanced user to get more information of image loading process) -
sd_internalSetImageWithURL:placeholderImage:options:operationKey:setImageBlock:progress:completed:context:removed - activity indicator refactoring - use
sd_imageIndicatorwithSDWebImageActivityIndicator-
sd_setShowActivityIndicatorView:removed -
sd_setIndicatorStyle:removed -
sd_showActivityIndicatorViewremoved -
sd_addActivityIndicator:removed -
sd_removeActivityIndicator:removed
-
- Renamed
isGIFtosd_isAnimated, alsoNSImage isGIFrenamed toNSImage sd_isAnimated - Renamed
decodedImageWithImage:tosd_decodedImageWithImage: - Renamed
decodedAndScaledDownImageWithImage:tosd_decodedAndScaledDownImageWithImage: - Renamed
sd_animatedGIFWithDatatosd_imageWithGIFData: - Removed
sd_webpLoopCount
- Removed
sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed
-
shouldDecompressImagesmoved toSDWebImageDownloaderConfig.shouldDecompressImages -
maxConcurrentDownloadsmoved toSDWebImageDownloaderConfig.maxConcurrentDownloads -
downloadTimeoutmoved toSDWebImageDownloaderConfig.downloadTimeout -
operationClassmoved toSDWebImageDownloaderConfig.operationClass -
executionOrdermoved toSDWebImageDownloaderConfig.executionOrder -
urlCredentialmoved toSDWebImageDownloaderConfig.urlCredential -
usernamemoved toSDWebImageDownloaderConfig.username -
passwordmoved toSDWebImageDownloaderConfig.password -
initWithSessionConfiguration:removed, useinitWithConfig:with session configuration instead -
createNewSessionWithConfiguration:removed, useinitWithConfig:with new session configuration instead. To modify shared downloader configuration, provide customSDWebImageDownloaderConfig.defaultDownloaderConfigbefore it created. -
headersFilterremoved, userequestModifierinstead -
cancel:removed, use-[SDWebImageDownloadToken cancel]instead -
shouldDecompressImagesremoved. UseSDWebImageDownloaderAvoidDecodeImagein downloader options instead - use
SDWebImageLoaderProgressBlockinstead ofSDWebImageDownloaderProgressBlock - use
SDWebImageLoaderCompletedBlockinstead ofSDWebImageDownloaderCompletedBlock
-
initWithRequest:inSession:options:context:is now the designated initializer - Removed
shouldUseCredentialStorageproperty -
SDWebImageDownloadOperationInterfaceprotocol renamed toSDWebImageDownloadOperation -
expectedSizeremoved, useresponse.expectedContentLengthinstead -
shouldDecompressImagesremoved. UseSDWebImageDownloaderAvoidDecodeImagein downloader options instead. -
responseproperty change to readonly
-
prefetchURLs:andprefetchURLs:progress:completed:return types changed fromvoidtoSDWebImagePrefetchToken -
prefetcherQueueproperty renamed todelegateQueue -
maxConcurrentDownloadsproperty removed, useSDWebImageManager.downloaderconfig instead
-
SDCGColorSpaceGetDeviceRGB()moved to+[SDImageCoderHelper colorSpaceGetDeviceRGB] -
SDCGImageRefContainsAlpha(), moved to+[SDImageCoderHelper imageRefContainsAlpha:] -
decodedImageWithData:replaced withdecodedImageWithData:options: -
encodedDataWithImage:format:replaced withencodedDataWithImage:format:options -
initmethod fromSDWebImageProgressiveCoderchanged toinitIncrementalWithOptions: -
incrementalDecodedImageWithData:finishedreplaced withupdateIncrementalData:finishedandincrementalDecodedImageWithOptions:two APIs - removed
decompressedImage:data:options, use+[SDImageCoderHelper decodedImageWithImage:]and+[SDImageCoderHelper decodedAndScaledDownImageWithImage:limitBytes:]instead
-
SDWebImageInternalSetImageGroupKeyrenamed toSDWebImageContextSetImageGroup -
SDWebImageExternalCustomManagerKeyrenamed toSDWebImageContextCustomManager
In SDWebImage 5.0 we did a clean up of the API. We are using many modern Objective-C declarations to generate the Swift API. We now provide full nullability support, string enum, class property, and even custom Swift API name, all to make the framework easier to use for our Swift users. Here are the API change specify for Swift.
-
sd_imageURL()changed tosd_imageURL
-
shared()changed toshared
-
shared()changed toshared -
isRunning()changed toisRunning
-
shared()changed toshared -
setOperationClass(_:)available for Swift user withoperationClassproperty -
setSuspended(_:)changed toisSuspendedproperty
-
SDWebImageDownloadOperationInterfaceprotocol renamed toSDWebImageDownloadOperationProtocol.
-
sharedInstance()changed toshared
-
shared()changed toshared
-
shared()changed toshared
-
shared()changed toshared
-
sd_UTTypeFromSDImageFormatreturnCFStringinstead ofUnmanaged<CFString>
-
sd_currentImageURL()changed tosd_currentImageURL
-
sd_currentImageURL()changed tosd_currentImageURL -
sd_currentAlternateImageURL()changed tosd_currentAlternateImageURL
For advanced user who need the detailed API diff, we provide the full diff in a HTML web page: SDWebImage 5.0 API Diff