Skip to content

A SDWebImage plugin to integrate YYImage & YYCache for image rendering & caching

License

Notifications You must be signed in to change notification settings

SDWebImage/SDWebImageYYPlugin

Repository files navigation

SDWebImageYYPlugin

CI Status Version License Platform Carthage compatible codecov

What's for

SDWebImageYYPlugin is a plugin for SDWebImage framework, which provide the image loading support for YYImage (including YYImage's decoding system and YYAnimatedImageView) and YYCache cache system.

By using SDWebImageYYPlugin, you can use all you familiar SDWebImage's loading method, on the YYAnimatedImageView.

And you can also use YYCache instead of SDImageCache for image cache system, which may better memory cache performance (By taking advanced of LRU algorithm), and disk cache performance (By taking advanced of sqlite blob storage)

Long term maintenance

This repo was created as a showcase how power the SDWebImage 5.0's customization can be. But actually is not recommended to use in commercial applications.

Since the upstream YYImage/YYCache has no longer maintained, and SDWebImage itself has become more and more performant than previous versions. I will not always up-to-date the compatibility with SDWebImage's internal changes from version to version. This repo will be deprecated in the future (like SDWebImage 6.0). But the PR for bugfix is still welcomed.

Usage

YYImage Plugin

To load a network image, simply call the View Category method like UIImageView.

  • Objective-C
YYAnimatedImageView *imageView;
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.gif"]];
  • Swift
let imageView: YYAnimatedImageView
imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.gif"))

For advanced user, you can embed YYImageDecoder && YYImageEncoder to SDWebImage by using the wrapper class SDImageYYCoder. See Custom Coder wiki in SDWebImage.

  • Objective-C
// Register YYImage decoder/encoder as coder plugin
[SDImageCodersManager.sharedManager addCoder:SDImageYYCoder.sharedCoder];
  • Swift
// Register YYImage decoder/encoder as coder plugin
SDImageCodersManager.shared.addCoder(SDImageYYCoder.shared)

YYCache Plugin

To enable YYCache instead of SDImageCache, you can bind the cache for shared manager, or create a custom manager instead.

  • Objective-C
// Use `YYCache` for shared manager
SDWebImageManger.defaultImageCache = [YYCache cacheWithName:@"name"];
  • Swift
// Use `YYCache` for shared manager
SDWebImageManger.defaultImageCache = YYCache(name: "name")

You can also use YYMemoryCache or YYDiskcache to customize memory cache / disk cache only. See Custom Cache wiki in SDWebImage.

  • Objective-C
// Use `YYMemoryCache` for shared `SDImageCache` memory cache implementation
SDImageCacheConfig.defaultCacheConfig.memoryCacheClass = YYMemoryCache.class;
// Use `YYDiskCache` for shared `SDImageCache` disk cache implementation
SDImageCacheConfig.defaultCacheConfig.diskCacheClass = YYDiskCache.class;
  • Swift
// Use `YYMemoryCache` for `SDImageCache` memory cache implementation
SDImageCacheConfig.default.memoryCacheClass = YYMemoryCache.self
// Use `YYDiskCache` for `SDImageCache` disk cache implementation
SDImageCacheConfig.default.diskCacheClass = YYDiskCache.self

Requirements

  • iOS 9+
  • Xcode 12+

Installation

CocoaPods

SDWebImageYYPlugin is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SDWebImageYYPlugin'

SDWebImageYYPlugin contains two subspecs, YYCache and YYImage. You can choose to enable only some of them. By default will contains all subspecs.

pod 'SDWebImageYYPlugin/YYImage'
pod 'SDWebImageYYPlugin/YYCache'

Carthage

SDWebImageFLPlugin is available through Carthage.

github "SDWebImage/SDWebImageYYPlugin"

Carthage does not support like CocoaPods' subspec, the built framework will contains both YYCache && YYImage support.

Note because of limit of YYImage Carthage support, YYImage plugin with Carthage will not support WebP format. If you want to support WebP format, use CocoaPods instead.

Author

DreamPiggy, [email protected]

License

SDWebImageYYPlugin is available under the MIT license. See the LICENSE file for more info.