SDWebImage 4.0 is the latest major release of SDWebImage, a top library for downloading and caching images.
As a major release, following [Semantic Versioning](http://semver.org/) conventions, 4.0 introduces several API-breaking changes with its new architecture.
Our support for animated images (especially GIFs) was not that great, so we decided to delegate this responsibility to [FLAnimatedImage](https://github.com/Flipboard/FLAnimatedImage), a library created by Flipboard which has great results in working with animated images.
This guide is provided in order to ease the transition of existing applications using SDWebImage 3.X to the latest APIs, as well as explain the design and structure of new and changed functionality.
-`SDImageCacheConfig` class for `SDImageCache` config (`shouldDecompressImages`, `shouldDisableiCloud`, `shouldCacheImagesInMemory`, `maxCacheAge`, `maxCacheSize`)
-`SDWebImageDownloadToken` class for the ability to cancel specific downloads (`url`, `downloadOperationCancelToken`)
-`UIView (WebCache)` category because of DRY, with methods
-`initWithCache:downloader:` is now the designated initializer
- added `SDWebImageScaleDownLargeImages` option for scaling large images
- renamed `downloadImageWithURL:options:progress:completed` to `loadImageWithURL:options:progress:completed` just to make it clear what the method does
- renamed `SDWebImageCompletionBlock` to `SDExternalCompletionBlock`
- renamed `SDWebImageCompletionWithFinishedBlock` to `SDInternalCompletionBlock` and added extra `NSData` param
- removed synchronous methods:
-`cachedImageExistsForURL:`
-`diskImageExistsForURL:`
- removed deprecated methods:
-`downloadWithURL:options:progress:completed:`
- removed deprecated types:
-`SDWebImageCompletedBlock`
-`SDWebImageCompletedWithFinishedBlock`
#### SDWebImagePrefetcher
-`initWithImageManager:` is now the designated initializer
#### SDWebImageDownloader
- added `initWithSessionConfiguration:` which is now the designated initializer
- added `SDWebImageDownloaderScaleDownLargeImages` option for scaling large images
- added a `NSURL` param to `SDWebImageDownloaderProgressBlock`
-`downloadImageWithURL:options:progress:completed:` now returns a `SDWebImageDownloadToken`
- added method `cancel:` which takes a `SDWebImageDownloadToken`
#### SDWebImageDownloaderOperation
-`initWithRequest:inSession:options:progress:completed:cancelled:` replaced by two methods: `initWithRequest:inSession:options:` and `addHandlersForProgress:completed:`
-`initWithRequest:inSession:options:` is now the designated initializer
- moved the following properties to `SDImageCacheConfig`:
-`shouldDecompressImages`
-`shouldDisableiCloud`
-`shouldCacheImagesInMemory`
-`maxCacheAge`
-`maxCacheSize`
- added a `config` property (`SDImageCacheConfig`)
- renamed `SDWebImageQueryCompletedBlock` to `SDCacheQueryCompletedBlock` and added `NSData` param
-`initWithNamespace:diskCacheDirectory:` is now the designated initializer
- the `storeImage:forKey:`, `storeImage:forKey:toDisk:`, `storeImage:recalculateFromImage:imageData:forKey:toDisk:` methods were async already, but declared as sync. Properly marked them as async + added `completion` param. Got rid of the `recalculate` param. If the `NSData` is provided, use it. Otherwise, recalculate it from the `UIImage`
- removed the synchronous method `diskImageExistsWithKey:`
- got rid of the confusion caused by having `cleanDisk` and `clearDisk`. Renamed `cleanDiskWithCompletion:` to `deleteOldFilesWithCompletion:`.
- removed the synchronous `clearDisk` and `deleteOldFiles`
- renamed `queryDiskCacheForKey:done:` to `queryCacheOperationForKey:done:`
- another clarification: `imageFromDiskCacheForKey:` used to also check the memory cache which I think is misleading. Now `imageFromDiskCacheForKey:` only checks the disk cache and the new method `imageFromCacheForKey:` checks both caches
- removed `removeImageForKey:` and `removeImageForKey:fromDisk:` because they caused confusion (were calling the async ones with `nil` as `completion`)
#### NSData (ImageContentType)
- renamed `sd_contentTypeForImageData:` to `sd_imageFormatForImageData:` and returns `SDImageFormat`
- removed the deprecated method `contentTypeForImageData:`
#### SDWebImageCompat
- removed `dispatch_main_sync_safe` as it could be mistakenly used
- updated `dispatch_main_async_safe` so it checks for the main queue instead of the main thread
#### SDWebImageDecoder
- added `decodedAndScaledDownImageWithImage:` that decodes the image and scales it down if it's too big (over 60MB in memory)
#### UIImage
- removed `sd_animatedGIFNamed:` or `sd_animatedImageByScalingAndCroppingToSize:`