Authored by Olivier Poitrey

Merge pull request #634 from burakkilic/patch-1

Update SDWebImagePrefetecher.m
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 @property (assign, nonatomic) NSUInteger finishedCount; 17 @property (assign, nonatomic) NSUInteger finishedCount;
18 @property (assign, nonatomic) NSTimeInterval startedTime; 18 @property (assign, nonatomic) NSTimeInterval startedTime;
19 @property (copy, nonatomic) void (^completionBlock)(NSUInteger, NSUInteger); 19 @property (copy, nonatomic) void (^completionBlock)(NSUInteger, NSUInteger);
  20 +@property (copy, nonatomic) void (^progressBlock)(NSUInteger, NSUInteger);
20 21
21 @end 22 @end
22 23
@@ -56,11 +57,13 @@ @@ -56,11 +57,13 @@
56 self.finishedCount++; 57 self.finishedCount++;
57 58
58 if (image) { 59 if (image) {
  60 + self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
59 #ifdef SD_VERBOSE 61 #ifdef SD_VERBOSE
60 NSLog(@"Prefetched %d out of %d", self.finishedCount, self.prefetchURLs.count); 62 NSLog(@"Prefetched %d out of %d", self.finishedCount, self.prefetchURLs.count);
61 #endif 63 #endif
62 } 64 }
63 else { 65 else {
  66 + self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
64 #ifdef SD_VERBOSE 67 #ifdef SD_VERBOSE
65 NSLog(@"Prefetched %d out of %d (Failed)", self.finishedCount, [self.prefetchURLs count]); 68 NSLog(@"Prefetched %d out of %d (Failed)", self.finishedCount, [self.prefetchURLs count]);
66 #endif 69 #endif
@@ -103,14 +106,15 @@ @@ -103,14 +106,15 @@
103 } 106 }
104 107
105 - (void)prefetchURLs:(NSArray *)urls { 108 - (void)prefetchURLs:(NSArray *)urls {
106 - [self prefetchURLs:urls completed:nil]; 109 + [self prefetchURLs:urls progress:nil completed:nil];
107 } 110 }
108 111
109 -- (void)prefetchURLs:(NSArray *)urls completed:(void (^)(NSUInteger, NSUInteger))completionBlock { 112 +- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock {
110 [self cancelPrefetching]; // Prevent duplicate prefetch request 113 [self cancelPrefetching]; // Prevent duplicate prefetch request
111 self.startedTime = CFAbsoluteTimeGetCurrent(); 114 self.startedTime = CFAbsoluteTimeGetCurrent();
112 self.prefetchURLs = urls; 115 self.prefetchURLs = urls;
113 self.completionBlock = completionBlock; 116 self.completionBlock = completionBlock;
  117 + self.progressBlock = progressBlock;
114 118
115 // Starts prefetching from the very first image on the list with the max allowed concurrency 119 // Starts prefetching from the very first image on the list with the max allowed concurrency
116 NSUInteger listCount = self.prefetchURLs.count; 120 NSUInteger listCount = self.prefetchURLs.count;