Skip to content
Browse files

Updated all block params and properties, using defined blocks that ha…

…ve var names (for proper autocomplete). Created a SDWebImageNoParamsBlock to distinguish easier from other no params blocks. Fixes #810
  • Loading branch information...
1 parent cd4b925 commit b88a552fbaa5cbdb907de6f75959ea5df0e035e0 @bpoplauschi bpoplauschi committed Jul 16, 2014
View
12 SDWebImage/SDImageCache.h
@@ -28,6 +28,8 @@ typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType ca
typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
+typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize);
+
/**
* SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
* asynchronous so it doesn’t add unnecessary latency to the UI.
@@ -136,7 +138,7 @@ typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
* @param key The unique image cache key
* @param completionBlock An block that should be executed after the image has been removed (optional)
*/
-- (void)removeImageForKey:(NSString *)key withCompletion:(void (^)())completion;
+- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion;
/**
* Remove the image from memory and optionally disk cache synchronously
@@ -153,7 +155,7 @@ typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
* @param fromDisk Also remove cache entry from disk if YES
* @param completionBlock An block that should be executed after the image has been removed (optional)
*/
-- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(void (^)())completion;
+- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion;
/**
* Clear all memory cached images
@@ -164,7 +166,7 @@ typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
* Clear all disk cached images. Non-blocking method - returns immediately.
* @param completionBlock An block that should be executed after cache expiration completes (optional)
*/
-- (void)clearDiskOnCompletion:(void (^)())completion;
+- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion;
/**
* Clear all disk cached images
@@ -176,7 +178,7 @@ typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
* Remove all expired cached image from disk. Non-blocking method - returns immediately.
* @param completionBlock An block that should be executed after cache expiration completes (optional)
*/
-- (void)cleanDiskWithCompletionBlock:(void (^)())completionBlock;
+- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock;
/**
* Remove all expired cached image from disk
@@ -197,7 +199,7 @@ typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
/**
* Asynchronously calculate the disk cache's size.
*/
-- (void)calculateSizeWithCompletionBlock:(void (^)(NSUInteger fileCount, NSUInteger totalSize))completionBlock;
+- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock;
/**
* Async check if image exists in disk cache already (does not load the image)
View
12 SDWebImage/SDImageCache.m
@@ -276,7 +276,7 @@ - (UIImage *)scaledImageForKey:(NSString *)key image:(UIImage *)image {
return SDScaledImageForKey(key, image);
}
-- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDImageCacheType cacheType))doneBlock {
+- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock {
if (!doneBlock) {
return nil;
}
@@ -319,15 +319,15 @@ - (void)removeImageForKey:(NSString *)key {
[self removeImageForKey:key withCompletion:nil];
}
-- (void)removeImageForKey:(NSString *)key withCompletion:(void (^)())completion {
+- (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion {
[self removeImageForKey:key fromDisk:YES withCompletion:completion];
}
- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk {
[self removeImageForKey:key fromDisk:fromDisk withCompletion:nil];
}
-- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(void (^)())completion {
+- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion {
if (key == nil) {
return;
@@ -367,7 +367,7 @@ - (void)clearDisk {
[self clearDiskOnCompletion:nil];
}
-- (void)clearDiskOnCompletion:(void (^)())completion
+- (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion
{
dispatch_async(self.ioQueue, ^{
[_fileManager removeItemAtPath:self.diskCachePath error:nil];
@@ -388,7 +388,7 @@ - (void)cleanDisk {
[self cleanDiskWithCompletionBlock:nil];
}
-- (void)cleanDiskWithCompletionBlock:(void (^)())completionBlock {
+- (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock {
dispatch_async(self.ioQueue, ^{
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
@@ -504,7 +504,7 @@ - (NSUInteger)getDiskCount {
return count;
}
-- (void)calculateSizeWithCompletionBlock:(void (^)(NSUInteger fileCount, NSUInteger totalSize))completionBlock {
+- (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock {
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
dispatch_async(self.ioQueue, ^{
View
2 SDWebImage/SDWebImageCompat.h
@@ -53,6 +53,8 @@
extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
+typedef void(^SDWebImageNoParamsBlock)();
+
#define dispatch_main_sync_safe(block)\
if ([NSThread isMainThread]) {\
block();\
View
4 SDWebImage/SDWebImageDownloader.h
@@ -72,6 +72,8 @@ typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteg
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
+typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers);
+
/**
* Asynchronous downloader dedicated and optimized for image loading.
*/
@@ -120,7 +122,7 @@ typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data,
* This block will be invoked for each downloading image request, returned
* NSDictionary will be used as headers in corresponding HTTP request.
*/
-@property (nonatomic, strong) NSDictionary *(^headersFilter)(NSURL *url, NSDictionary *headers);
+@property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter;
/**
* Set a value for a HTTP header to be appended to each download HTTP request.
View
4 SDWebImage/SDWebImageDownloader.m
@@ -104,7 +104,7 @@ - (NSInteger)maxConcurrentDownloads {
return _downloadQueue.maxConcurrentOperationCount;
}
-- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSInteger, NSInteger))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock {
+- (id <SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
__block SDWebImageDownloaderOperation *operation;
__weak SDWebImageDownloader *wself = self;
@@ -174,7 +174,7 @@ - (NSInteger)maxConcurrentDownloads {
return operation;
}
-- (void)addProgressCallback:(void (^)(NSInteger, NSInteger))progressBlock andCompletedBlock:(void (^)(UIImage *, NSData *data, NSError *, BOOL))completedBlock forURL:(NSURL *)url createCallback:(void (^)())createCallback {
+- (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock andCompletedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
// The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data.
if (url == nil) {
if (completedBlock != nil) {
View
2 SDWebImage/SDWebImageDownloaderOperation.h
@@ -55,6 +55,6 @@
options:(SDWebImageDownloaderOptions)options
progress:(SDWebImageDownloaderProgressBlock)progressBlock
completed:(SDWebImageDownloaderCompletedBlock)completedBlock
- cancelled:(void (^)())cancelBlock;
+ cancelled:(SDWebImageNoParamsBlock)cancelBlock;
@end
View
8 SDWebImage/SDWebImageDownloaderOperation.m
@@ -16,7 +16,7 @@ @interface SDWebImageDownloaderOperation () <NSURLConnectionDataDelegate>
@property (copy, nonatomic) SDWebImageDownloaderProgressBlock progressBlock;
@property (copy, nonatomic) SDWebImageDownloaderCompletedBlock completedBlock;
-@property (copy, nonatomic) void (^cancelBlock)();
+@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
@property (assign, nonatomic, getter = isExecuting) BOOL executing;
@property (assign, nonatomic, getter = isFinished) BOOL finished;
@@ -40,7 +40,11 @@ @implementation SDWebImageDownloaderOperation {
@synthesize executing = _executing;
@synthesize finished = _finished;
-- (id)initWithRequest:(NSURLRequest *)request options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSInteger, NSInteger))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock cancelled:(void (^)())cancelBlock {
+- (id)initWithRequest:(NSURLRequest *)request
+ options:(SDWebImageDownloaderOptions)options
+ progress:(SDWebImageDownloaderProgressBlock)progressBlock
+ completed:(SDWebImageDownloaderCompletedBlock)completedBlock
+ cancelled:(SDWebImageNoParamsBlock)cancelBlock {
if ((self = [super init])) {
_request = request;
_shouldUseCredentialStorage = YES;
View
4 SDWebImage/SDWebImageManager.h
@@ -81,6 +81,8 @@ typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImage
typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
+typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
+
@class SDWebImageManager;
@@ -157,7 +159,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
* @endcode
*/
-@property (strong) NSString *(^cacheKeyFilter)(NSURL *url);
+@property (copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
/**
* Returns global SDWebImageManager instance.
View
4 SDWebImage/SDWebImageManager.m
@@ -12,7 +12,7 @@
@interface SDWebImageCombinedOperation : NSObject <SDWebImageOperation>
@property (assign, nonatomic, getter = isCancelled) BOOL cancelled;
-@property (copy, nonatomic) void (^cancelBlock)();
+@property (copy, nonatomic) SDWebImageNoParamsBlock cancelBlock;
@property (strong, nonatomic) NSOperation *cacheOperation;
@end
@@ -297,7 +297,7 @@ - (BOOL)isRunning {
@implementation SDWebImageCombinedOperation
-- (void)setCancelBlock:(void (^)())cancelBlock {
+- (void)setCancelBlock:(SDWebImageNoParamsBlock)cancelBlock {
if (self.isCancelled) {
if (cancelBlock) cancelBlock();
}
View
6 SDWebImage/SDWebImagePrefetcher.h
@@ -35,6 +35,8 @@
@end
+typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
+typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
/**
* Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
@@ -82,8 +84,10 @@
* first parameter is the number of completed (successful or not) requests,
* second parameter is the total number of images originally requested to be prefetched
* @param completionBlock block to be called when prefetching is completed
+ * first param is the number of completed (successful or not) requests,
+ * second parameter is the number of skipped requests
*/
-- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock;
+- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
/**
* Remove and cancel queued list
View
6 SDWebImage/SDWebImagePrefetcher.m
@@ -20,8 +20,8 @@ @interface SDWebImagePrefetcher ()
@property (assign, nonatomic) NSUInteger skippedCount;
@property (assign, nonatomic) NSUInteger finishedCount;
@property (assign, nonatomic) NSTimeInterval startedTime;
-@property (copy, nonatomic) void (^completionBlock)(NSUInteger, NSUInteger);
-@property (copy, nonatomic) void (^progressBlock)(NSUInteger, NSUInteger);
+@property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
+@property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
@end
@@ -113,7 +113,7 @@ - (void)prefetchURLs:(NSArray *)urls {
[self prefetchURLs:urls progress:nil completed:nil];
}
-- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock {
+- (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
[self cancelPrefetching]; // Prevent duplicate prefetch request
self.startedTime = CFAbsoluteTimeGetCurrent();
self.prefetchURLs = urls;

0 comments on commit b88a552

Please sign in to comment.
Something went wrong with that request. Please try again.