Parcourir la source

Created `SDWebImageDownloaderOperationInterface` to describe the behavior of a downloader operation. Any custom operation must conform to this protocol.

Bogdan Poplauschi il y a 9 ans
Parent
commit
df3b6a5
2 fichiers modifiés avec 29 ajouts et 2 suppressions
  1. 5 1
      SDWebImage/SDWebImageDownloader.m
  2. 24 1
      SDWebImage/SDWebImageDownloaderOperation.h

+ 5 - 1
SDWebImage/SDWebImageDownloader.m

@@ -129,7 +129,11 @@
 }
 
 - (void)setOperationClass:(nullable Class)operationClass {
-    _operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
+    if (operationClass && [operationClass isSubclassOfClass:[NSOperation class]] && [operationClass conformsToProtocol:@protocol(SDWebImageDownloaderOperationInterface)]) {
+        _operationClass = operationClass;
+    } else {
+        _operationClass = [SDWebImageDownloaderOperation class];
+    }
 }
 
 - (nullable SDWebImageDownloadToken *)downloadImageWithURL:(nullable NSURL *)url

+ 24 - 1
SDWebImage/SDWebImageDownloaderOperation.h

@@ -15,7 +15,30 @@ extern NSString * _Nonnull const SDWebImageDownloadReceiveResponseNotification;
 extern NSString * _Nonnull const SDWebImageDownloadStopNotification;
 extern NSString * _Nonnull const SDWebImageDownloadFinishNotification;
 
-@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
+
+
+/**
+ Describes a downloader operation. If one wants to use a custom downloader op, it needs to inherit from `NSOperation` and conform to this protocol
+ */
+@protocol SDWebImageDownloaderOperationInterface<NSObject>
+
+- (nonnull instancetype)initWithRequest:(nullable NSURLRequest *)request
+                              inSession:(nullable NSURLSession *)session
+                                options:(SDWebImageDownloaderOptions)options;
+
+- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
+                            completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
+
+- (BOOL)shouldDecompressImages;
+- (void)setShouldDecompressImages:(BOOL)value;
+
+- (nullable NSURLCredential *)credential;
+- (void)setCredential:(nullable NSURLCredential *)value;
+
+@end
+
+
+@interface SDWebImageDownloaderOperation : NSOperation <SDWebImageDownloaderOperationInterface, SDWebImageOperation, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
 
 /**
  * The request used by the operation's task.