12 KiB
SDWebImage 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.
Requirements: iOS 8, Mac OS X 10.10, watchOS 2, tvOS 9, Xcode 9
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.
Migration
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 view loading as well as many aspect. See the declaration for SDWebImageContext
for detailed information.
New Features
Animated Image View
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.
Transformer
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.
Customization
In 5.0, we refactor our framework architecture, to allow it easy to customize for advanced user, without breaking anything or create their fork. We introduce Custom Cache, Custom Loader, and make current Custom Coder works better for these developers.
FLAnimatedImage support moved to a dedicated plugin repo
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.
Photos Plugin
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.
API Changes
SDImageCache
- moved
maxMemoryCost
andmaxMemoryCountLimit
toSDImageCacheConfig
makeDiskCachePath:
removed, useNSSearchPathForDirectoriesInDomains
with NSString's Path API instead.addReadOnlyCachePath:
removed, useadditionalCachePathBlock
insteadcachePathForKey:inPath:
removed, usecachePathForKey:
with NSString's path API instead.defaultCachePathForKey:
removed, usecachePathForKey:
insteadSDCacheQueryCompletedBlock
renamed toSDImageCacheQueryCompletionBlock
SDWebImageCheckCacheCompletionBlock
renamed toSDImageCacheCheckCompletionBlock
SDWebImageCalculateSizeBlock
renamed toSDImageCacheCalculateSizeBlock
SDImageCacheConfig
shouldDecompressImages
removed. UseSDImageCacheAvoidDecodeImage
in cache options instead
SDWebImageManager
loadImageWithURL:options:progress:completed:
changed thecompleted
param requirement fromnullable
tononnull
loadImageWithURL:options:progress:completed:
return typeid<SDWebImageOperation>
changed toSDWebImageCombinedOperation *
imageCache
changed from nullable to nonnull. And property type changed fromSDImageCache *
toid<SDImageCache>
. The default value does not change.imageDownloader
renamed toimageLoader
and changed from nullable to nonnull. And property type changed fromSDWebImageDownloader *
toid<SDImageLoader>
. The default value does not change.cacheKeyFilter
property type changed toid<SDWebImageCacheKeyFilter>
, you can use+[SDWebImageCacheKeyFilter cacheKeyFilterWithBlock:]
to createcacheSerializer
property type changed toid<SDWebImageCacheSerializer>
, you can use+[SDWebImageCacheSerializer cacheSerializerWithBlock:]
to createSDWebImageCacheKeyFilterBlock
'surl
arg change from nullable to nonnullinitWithCache:downloader:
'scache
arg type changed fromSDImageCache *
toid<SDImageCache>
initWithCache:downloader
renamed 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:completion
removed. UseSDImageCache containsImageForKey:cacheType:completion:
(orSDImageCache diskImageExistsWithKey:completion:
andSDImageCache imageFromMemoryCacheForKey:
if you use default cache class) withcacheKeyForURL:
instead.
SDWebImageManagerDelegate
- removed
imageManager:transformDownloadedImage:forKey:
, useSDImageTransformer
with context option instead
UIView and subclasses (UIImageView, UIButton, ...)
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 fromSDExternalCompletionBlock
toSDInternalCompletionBlock
. 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_imageIndicator
withSDWebImageActivityIndicator
sd_setShowActivityIndicatorView:
removedsd_setIndicatorStyle:
removedsd_showActivityIndicatorView
removedsd_addActivityIndicator:
removedsd_removeActivityIndicator:
removed
UIImage
- Renamed
isGIF
tosd_isAnimated
, alsoNSImage isGIF
renamed toNSImage sd_isAnimated
- Renamed
decodedImageWithImage:
tosd_decodedImageWithImage:
- Renamed
decodedAndScaledDownImageWithImage:
tosd_decodedAndScaledDownImageWithImage:
- Renamed
sd_animatedGIFWithData
tosd_imageWithGIFData:
- Removed
sd_webpLoopCount
UIImageView
- Removed
sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed
SDWebImageDownloader
shouldDecompressImages
moved toSDWebImageDownloaderConfig.shouldDecompressImages
maxConcurrentDownloads
moved toSDWebImageDownloaderConfig.maxConcurrentDownloads
downloadTimeout
moved toSDWebImageDownloaderConfig.downloadTimeout
operationClass
moved toSDWebImageDownloaderConfig.operationClass
executionOrder
moved toSDWebImageDownloaderConfig.executionOrder
urlCredential
moved toSDWebImageDownloaderConfig.urlCredential
username
moved toSDWebImageDownloaderConfig.username
password
moved toSDWebImageDownloaderConfig.password
initWithSessionConfiguration:
removed, useinitWithConfig:
with session configuration insteadcreateNewSessionWithConfiguration:
removed, useinitWithConfig:
with new session configuration instead. To modify shared downloader configuration, provide customSDWebImageDownloaderConfig.defaultDownloaderConfig
before it created.headersFilter
removed, userequestModifier
insteadcancel:
removed, use-[SDWebImageDownloadToken cancel]
insteadshouldDecompressImages
removed. UseSDWebImageDownloaderAvoidDecodeImage
in downloader options instead- use
SDWebImageLoaderProgressBlock
instead ofSDWebImageDownloaderProgressBlock
- use
SDWebImageLoaderCompletedBlock
instead ofSDWebImageDownloaderCompletedBlock
SDWebImageDownloaderOperation
initWithRequest:inSession:options:context:
is now the designated initializer- Removed
shouldUseCredentialStorage
property SDWebImageDownloadOperationInterface
protocol renamed toSDWebImageDownloadOperation
expectedSize
removed, useresponse.expectedContentLength
insteadshouldDecompressImages
removed. UseSDWebImageDownloaderAvoidDecodeImage
in downloader options instead.response
property change to readonly
SDWebImagePrefetcher
prefetchURLs:
andprefetchURLs:progress:completed:
return types changed fromvoid
toSDWebImagePrefetchToken
prefetcherQueue
property renamed todelegateQueue
maxConcurrentDownloads
property removed, useSDWebImageManager.downloader
config instead
SDImageCoder
SDCGColorSpaceGetDeviceRGB()
moved to+[SDImageCoderHelper colorSpaceGetDeviceRGB]
SDCGImageRefContainsAlpha()
, moved to+[SDImageCoderHelper imageRefContainsAlpha:]
decodedImageWithData:
replaced withdecodedImageWithData:options:
encodedDataWithImage:format:
replaced withencodedDataWithImage:format:options
init
method fromSDWebImageProgressiveCoder
changed toinitIncrementalWithOptions:
incrementalDecodedImageWithData:finished
replaced withupdateIncrementalData:finished
andincrementalDecodedImageWithOptions:
two APIs- removed
decompressedImage:data:options
, use+[SDImageCoderHelper decodedImageWithImage:]
and+[SDImageCoderHelper decodedAndScaledDownImageWithImage:limitBytes:]
instead
Constants
SDWebImageInternalSetImageGroupKey
renamed toSDWebImageContextSetImageGroup
SDWebImageExternalCustomManagerKey
renamed toSDWebImageContextCustomManager
Swift Specific API Changes
We did a full cleanup of the Swift APIs. 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.
UIView+WebCache
sd_imageURL()
changed tosd_imageURL
SDWebImageManager
shared()
changed toshared
isRunning()
changed toisRunning
SDWebImageDownloader
shared()
changed toshared
setOperationClass(_:)
available for Swift user withoperationClass
propertysetSuspended(_:)
changed toisSuspended
property
SDWebImageDownloadOperation
SDWebImageDownloadOperationInterface
protocol renamed toSDWebImageDownloadOperationProtocol
.
SDImageCodersManager
sharedInstance()
changed toshared
SDImageIOCoder
shared()
changed toshared
SDImageGIFCoder
shared()
changed toshared
SDImageWebPCoder
shared()
changed toshared
NSData-ImageContentType
sd_UTTypeFromSDImageFormat
returnCFString
instead ofUnmanaged<CFString>
UIButton-WebCache
sd_currentImageURL()
changed tosd_currentImageURL
NSButton-WebCache
sd_currentImageURL()
changed tosd_currentImageURL
sd_currentAlternateImageURL()
changed tosd_currentAlternateImageURL
Full API Diff
For advanced user who need the detailed API diff, we provide the full diff in a HTML web page: SDWebImage 5.0 API Diff