8.5 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.
.... RELEASE_SUMMARY ....
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 8
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 8 or later to be able to build everything properly.
For targeting previous versions of the SDKs, check README - Backwards compatibility .
Migration
Swift
Objective-C
example
SDWebImage 4.x
[imageView sd_setImageWithURL:url placeholderImage:placeholderImage];
SDWebImage 5.x
[imageView sd_setImageWithURL:url placeholderImage:placeholderImage];
Entities
Added
...
SDImageCache
- new initializer
initWithNamespace:diskCacheDirectory:config:
, is now the designated initializer - moved
maxMemoryCost
andmaxMemoryCountLimit
toSDImageCacheConfig
- added
SDImageCache diskImageDataExistsWithKey:
synchronous method addReadOnlyCachePath:
removed, useadditionalCachePathBlock
insteadcachePathForKey:inPath:
removed, usecachePathForKey:
with NSString's path API instead.defaultCachePathForKey:
removed, usecachePathForKey:
instead
SDImageCacheConfig
- added
diskCacheWritingOptions
of typeNSDataWritingOptions
, defaults toNSDataWritingAtomic
- added
maxMemoryCost
andmaxMemoryCountLimit
properties (used to be inSDImageCache
) 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 *
shared()
changed toshared
isRunning()
changed toisRunning
imageCache
changed from nullable to nonnullimageDownloader
renamed toimageLoader
and changed from nullable to nonnullcacheKeyFilter
property type changed toid<SDWebImageCacheKeyFilter>
, use theSDWebImageCacheKeyFilter cacheKeyFilterWithBlock:
cacheSerializer
property type CHANGED toid<SDWebImageCacheSerializer>
, use theSDWebImageCacheSerializer cacheSerializerWithBlock:
imageCache
property type changed fromSDImageCache *
toid<SDImageCache>
. The default value does not change.initWithCache: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:
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:
- Removed
sd_webpLoopCount
since we havesd_imageLoopCount
UIImageView
- Removed
sd_setImageWithPreviousCachedImageWithURL:placeholderImage:options:progress:completed
SDWebImageDownloader
shared()
changed toshared
setOperationClass
available for Swift usersetSuspended(_:)
changed toisSuspended
propertyshouldDecompressImages
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, useSDWebImageDownloadToken cancel
insteadshouldDecompressImages
removed. UseSDWebImageDownloaderAvoidDecodeImage
in downloader options instead
SDWebImageDownloaderOperation
initWithRequest:inSession:options:context:
is now the designated initializer- Removed
shouldUseCredentialStorage
property SDWebImageDownloadOperationInterface
protocol renamed toSDWebImageDownloadOperation
. (SDWebImageDownloadOperationProtocol
for Swift)expectedSize
removed, useresponse.expectedContentLength
insteadshouldDecompressImages
removed. UseSDWebImageDownloaderAvoidDecodeImage
in downloader options instead.
SDWebImagePrefetcher
prefetchURLs:
andprefetchURLs:progress:completed:
return types changed fromvoid
toSDWebImagePrefetchToken
prefetcherQueue
property renamed todelegateQueue
maxConcurrentDownloads
property removed, useSDWebImageManager.downloader
config instead
SDWebImageCoder
SDCGColorSpaceGetDeviceRGB()
moved toSDWebImageCoderHelper colorSpaceGetDeviceRGB
SDCGImageRefContainsAlpha()
, moved toSDWebImageCoderHelper imageRefContainsAlpha:
decodedImageWithData:
replaced withdecodedImageWithData:options:
encodedDataWithImage:format:
replaced withencodedDataWithImage:format:options
init
method fromSDWebImageProgressiveCoder
changed toinitIncrementalWithOptions:
incrementalDecodedImageWithData:finished
replaced withupdateIncrementalData:finished
andincrementalDecodedImageWithOptions:
- removed
decompressedImage:data:options
SDWebImageCodersManager
sharedInstance()
changed toshared
SDWebImageImageIOCoder
shared()
changed toshared
SDWebImageGIFCoder
shared()
changed toshared
SDWebImageWebPCoder
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
Constants
SDWebImageInternalSetImageGroupKey
renamed toSDWebImageContextSetImageGroup
SDWebImageExternalCustomManagerKey
renamed toSDWebImageContextCustomManager