Change all sharedInstance from method to class property
This commit is contained in:
parent
e0ad0711da
commit
c9dfe39e36
|
@ -26,7 +26,7 @@
|
|||
[super viewDidLoad];
|
||||
|
||||
//Add GIF coder for better animated image rendering
|
||||
[[SDWebImageCodersManager sharedInstance] addCoder:[SDWebImageGIFCoder sharedCoder]];
|
||||
[[SDWebImageCodersManager sharedManager] addCoder:[SDWebImageGIFCoder sharedCoder]];
|
||||
|
||||
// NOTE: https links or authentication ones do not work (there is a crash)
|
||||
|
||||
|
|
|
@ -62,10 +62,8 @@ typedef void(^SDWebImageCompletionWithPossibleErrorBlock)(NSError * _Nullable er
|
|||
|
||||
/**
|
||||
* Returns global shared cache instance
|
||||
*
|
||||
* @return SDImageCache global instance
|
||||
*/
|
||||
+ (nonnull instancetype)sharedImageCache;
|
||||
@property (nonatomic, class, readonly, nonnull) SDImageCache *sharedImageCache;
|
||||
|
||||
/**
|
||||
* Init a new cache store with a specific namespace
|
||||
|
|
|
@ -298,7 +298,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
} else {
|
||||
format = SDImageFormatJPEG;
|
||||
}
|
||||
data = [[SDWebImageCodersManager sharedInstance] encodedDataWithImage:image format:format];
|
||||
data = [[SDWebImageCodersManager sharedManager] encodedDataWithImage:image format:format];
|
||||
}
|
||||
[self _storeImageDataToDisk:data forKey:key error:&writeError];
|
||||
}
|
||||
|
@ -475,10 +475,10 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
|
||||
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key data:(nullable NSData *)data {
|
||||
if (data) {
|
||||
UIImage *image = [[SDWebImageCodersManager sharedInstance] decodedImageWithData:data];
|
||||
UIImage *image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:data];
|
||||
image = [self scaledImageForKey:key image:image];
|
||||
if (self.config.shouldDecompressImages) {
|
||||
image = [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&data options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}];
|
||||
image = [[SDWebImageCodersManager sharedManager] decompressedImageWithImage:image data:&data options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}];
|
||||
}
|
||||
return image;
|
||||
} else {
|
||||
|
|
|
@ -32,9 +32,9 @@
|
|||
@interface SDWebImageCodersManager : NSObject<SDWebImageCoder>
|
||||
|
||||
/**
|
||||
Shared reusable instance
|
||||
Returns the global shared coders manager instance.
|
||||
*/
|
||||
+ (nonnull instancetype)sharedInstance;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageCodersManager *sharedManager;
|
||||
|
||||
/**
|
||||
All coders in coders manager. The coders array is a priority queue, which means the later added coder will have the highest priority
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
@implementation SDWebImageCodersManager
|
||||
|
||||
+ (nonnull instancetype)sharedInstance {
|
||||
+ (nonnull instancetype)sharedManager {
|
||||
static dispatch_once_t once;
|
||||
static id instance;
|
||||
dispatch_once(&once, ^{
|
||||
|
|
|
@ -183,11 +183,9 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB
|
|||
@property (nonatomic, copy, nullable) SDWebImageDownloaderHeadersFilterBlock headersFilter;
|
||||
|
||||
/**
|
||||
* Singleton method, returns the shared instance
|
||||
*
|
||||
* @return global shared instance of downloader class
|
||||
* Returns the global shared downloader instance
|
||||
*/
|
||||
+ (nonnull instancetype)sharedDownloader;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageDownloader *sharedDownloader;
|
||||
|
||||
/**
|
||||
* Creates an instance of a downloader with specified session configuration.
|
||||
|
|
|
@ -345,7 +345,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
|
||||
if (!self.progressiveCoder) {
|
||||
// We need to create a new instance for progressive decoding to avoid conflicts
|
||||
for (id<SDWebImageCoder>coder in [SDWebImageCodersManager sharedInstance].coders) {
|
||||
for (id<SDWebImageCoder>coder in [SDWebImageCodersManager sharedManager].coders) {
|
||||
if ([coder conformsToProtocol:@protocol(SDWebImageProgressiveCoder)] &&
|
||||
[((id<SDWebImageProgressiveCoder>)coder) canIncrementallyDecodeFromData:imageData]) {
|
||||
self.progressiveCoder = [[[coder class] alloc] init];
|
||||
|
@ -361,7 +361,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||
image = [self scaledImageForKey:key image:image];
|
||||
if (self.shouldDecompressImages) {
|
||||
image = [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&imageData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}];
|
||||
image = [[SDWebImageCodersManager sharedManager] decompressedImageWithImage:image data:&imageData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}];
|
||||
}
|
||||
|
||||
// We do not keep the progressive decoding image even when `finished`=YES. Because they are for view rendering but not take full function from downloader options. And some coders implementation may not keep consistent between progressive decoding and normal decoding.
|
||||
|
@ -427,7 +427,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
} else {
|
||||
// decode the image in coder queue
|
||||
dispatch_async(self.coderQueue, ^{
|
||||
UIImage *image = [[SDWebImageCodersManager sharedInstance] decodedImageWithData:imageData];
|
||||
UIImage *image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:imageData];
|
||||
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
|
||||
image = [self scaledImageForKey:key image:image];
|
||||
|
||||
|
@ -447,7 +447,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
if (shouldDecode) {
|
||||
if (self.shouldDecompressImages) {
|
||||
BOOL shouldScaleDown = self.options & SDWebImageDownloaderScaleDownLargeImages;
|
||||
image = [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&imageData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(shouldScaleDown)}];
|
||||
image = [[SDWebImageCodersManager sharedManager] decompressedImageWithImage:image data:&imageData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(shouldScaleDown)}];
|
||||
}
|
||||
}
|
||||
CGSize imageSize = image.size;
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
*/
|
||||
@interface SDWebImageGIFCoder : NSObject <SDWebImageCoder>
|
||||
|
||||
+ (nonnull instancetype)sharedCoder;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageGIFCoder *sharedCoder;
|
||||
|
||||
@end
|
||||
|
|
|
@ -25,6 +25,6 @@
|
|||
*/
|
||||
@interface SDWebImageImageIOCoder : NSObject <SDWebImageProgressiveCoder>
|
||||
|
||||
+ (nonnull instancetype)sharedCoder;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageImageIOCoder *sharedCoder;
|
||||
|
||||
@end
|
||||
|
|
|
@ -213,11 +213,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
@property (nonatomic, copy, nullable) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
|
||||
|
||||
/**
|
||||
* Returns global SDWebImageManager instance.
|
||||
*
|
||||
* @return SDWebImageManager shared instance
|
||||
* Returns global shared manager instance.
|
||||
*/
|
||||
+ (nonnull instancetype)sharedManager;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageManager *sharedManager;
|
||||
|
||||
/**
|
||||
* Allows to specify instance of cache and image downloader used with image manager.
|
||||
|
|
|
@ -80,9 +80,9 @@ typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls,
|
|||
@property (weak, nonatomic, nullable) id <SDWebImagePrefetcherDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Return the global image prefetcher instance.
|
||||
* Returns the global shared image prefetcher instance.
|
||||
*/
|
||||
+ (nonnull instancetype)sharedImagePrefetcher;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImagePrefetcher *sharedImagePrefetcher;
|
||||
|
||||
/**
|
||||
* Allows you to instantiate a prefetcher with any arbitrary image manager.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
@interface SDWebImageWebPCoder : NSObject <SDWebImageProgressiveCoder>
|
||||
|
||||
+ (nonnull instancetype)sharedCoder;
|
||||
@property (nonatomic, class, readonly, nonnull) SDWebImageWebPCoder *sharedCoder;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
return nil;
|
||||
}
|
||||
NSData *tempData;
|
||||
return [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&tempData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}];
|
||||
return [[SDWebImageCodersManager sharedManager] decompressedImageWithImage:image data:&tempData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(NO)}];
|
||||
}
|
||||
|
||||
+ (UIImage *)sd_decodedAndScaledDownImageWithImage:(UIImage *)image {
|
||||
|
@ -24,7 +24,7 @@
|
|||
return nil;
|
||||
}
|
||||
NSData *tempData;
|
||||
return [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&tempData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(YES)}];
|
||||
return [[SDWebImageCodersManager sharedManager] decompressedImageWithImage:image data:&tempData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(YES)}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
@implementation UIImage (MultiFormat)
|
||||
|
||||
+ (nullable UIImage *)sd_imageWithData:(nullable NSData *)data {
|
||||
return [[SDWebImageCodersManager sharedInstance] decodedImageWithData:data];
|
||||
return [[SDWebImageCodersManager sharedManager] decodedImageWithData:data];
|
||||
}
|
||||
|
||||
- (nullable NSData *)sd_imageData {
|
||||
|
@ -22,7 +22,7 @@
|
|||
- (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat {
|
||||
NSData *imageData = nil;
|
||||
if (self) {
|
||||
imageData = [[SDWebImageCodersManager sharedInstance] encodedDataWithImage:self format:imageFormat];
|
||||
imageData = [[SDWebImageCodersManager sharedManager] encodedDataWithImage:self format:imageFormat];
|
||||
}
|
||||
return imageData;
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"Custom decoder for SDImageCache not works"];
|
||||
SDImageCache *cache = [[SDImageCache alloc] initWithNamespace:@"TestDecode"];
|
||||
SDWebImageTestDecoder *testDecoder = [[SDWebImageTestDecoder alloc] init];
|
||||
[[SDWebImageCodersManager sharedInstance] addCoder:testDecoder];
|
||||
[[SDWebImageCodersManager sharedManager] addCoder:testDecoder];
|
||||
NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
|
||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
||||
NSString *key = @"TestPNGImageEncodedToDataAndRetrieveToJPEG";
|
||||
|
@ -298,7 +298,7 @@ NSString *kImageTestKey = @"TestImageKey.jpg";
|
|||
XCTFail(@"Custom decoder not work for SDImageCache, check -[SDWebImageTestDecoder decodedImageWithData:]");
|
||||
}
|
||||
|
||||
[[SDWebImageCodersManager sharedInstance] removeCoder:testDecoder];
|
||||
[[SDWebImageCodersManager sharedManager] removeCoder:testDecoder];
|
||||
|
||||
[[SDImageCache sharedImageCache] removeImageForKey:key withCompletion:^{
|
||||
[expectation fulfill];
|
||||
|
|
|
@ -366,7 +366,7 @@
|
|||
XCTestExpectation *expectation = [self expectationWithDescription:@"Custom decoder for SDWebImageDownloader not works"];
|
||||
SDWebImageDownloader *downloader = [[SDWebImageDownloader alloc] init];
|
||||
SDWebImageTestDecoder *testDecoder = [[SDWebImageTestDecoder alloc] init];
|
||||
[[SDWebImageCodersManager sharedInstance] addCoder:testDecoder];
|
||||
[[SDWebImageCodersManager sharedManager] addCoder:testDecoder];
|
||||
NSURL * testImageURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"png"];
|
||||
|
||||
// Decoded result is JPEG
|
||||
|
@ -384,7 +384,7 @@
|
|||
if (![str1 isEqualToString:str2]) {
|
||||
XCTFail(@"The image data is not modified by the custom decoder, check -[SDWebImageTestDecoder decompressedImageWithImage:data:options:]");
|
||||
}
|
||||
[[SDWebImageCodersManager sharedInstance] removeCoder:testDecoder];
|
||||
[[SDWebImageCodersManager sharedManager] removeCoder:testDecoder];
|
||||
[expectation fulfill];
|
||||
}];
|
||||
|
||||
|
|
Loading…
Reference in New Issue