From 9112170ea3f4084564c100a97fe828f654f2750c Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Mon, 30 May 2016 07:31:01 +0300 Subject: [PATCH] Replaces #1398 Allow to customise cache and image downloader instances used with SDWebImageManager - added a new initializer (`initWithCache:downloader:`) --- SDWebImage/SDWebImageManager.h | 6 ++++++ SDWebImage/SDWebImageManager.m | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 4a9e6f38..7edfc74c 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -181,6 +181,12 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; */ + (SDWebImageManager *)sharedManager; +/** + * Allows to specify instance of cache and image downloader used with image manager. + * @return new instance of `SDWebImageManager` with specified cache and downloader. + */ +- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader; + /** * Downloads the image at the given URL if not present in cache or return the cached version otherwise. * diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 70c03a1d..1f9a3a96 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -38,19 +38,21 @@ } - (instancetype)init { + SDImageCache *cache = [SDImageCache sharedImageCache]; + SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader]; + return [self initWithCache:cache downloader:downloader]; +} + +- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader { if ((self = [super init])) { - _imageCache = [self createCache]; - _imageDownloader = [SDWebImageDownloader sharedDownloader]; + _imageCache = cache; + _imageDownloader = downloader; _failedURLs = [NSMutableSet new]; _runningOperations = [NSMutableArray new]; } return self; } -- (SDImageCache *)createCache { - return [SDImageCache sharedImageCache]; -} - - (NSString *)cacheKeyForURL:(NSURL *)url { if (self.cacheKeyFilter) { return self.cacheKeyFilter(url);