@@ -17,6 +17,7 @@ @interface SDWebImagePrefetcher ()
1717@property (assign , nonatomic ) NSUInteger finishedCount;
1818@property (assign , nonatomic ) NSTimeInterval startedTime;
1919@property (copy , nonatomic ) void (^completionBlock)(NSUInteger , NSUInteger );
20+ @property (copy , nonatomic ) void (^progressBlock)(NSUInteger , NSUInteger );
2021
2122@end
2223
@@ -56,11 +57,13 @@ - (void)startPrefetchingAtIndex:(NSUInteger)index {
5657 self.finishedCount ++;
5758
5859 if (image) {
60+ self.progressBlock (self.finishedCount ,[self .prefetchURLs count ]);
5961#ifdef SD_VERBOSE
6062 NSLog (@" Prefetched %d out of %d " , self.finishedCount , self.prefetchURLs .count );
6163#endif
6264 }
6365 else {
66+ self.progressBlock (self.finishedCount ,[self .prefetchURLs count ]);
6467#ifdef SD_VERBOSE
6568 NSLog (@" Prefetched %d out of %d (Failed)" , self.finishedCount , [self .prefetchURLs count ]);
6669#endif
@@ -103,14 +106,15 @@ - (void)reportStatus {
103106}
104107
105108- (void )prefetchURLs : (NSArray *)urls {
106- [self prefetchURLs: urls completed: nil ];
109+ [self prefetchURLs: urls progress: nil completed: nil ];
107110}
108111
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 {
110113 [self cancelPrefetching ]; // Prevent duplicate prefetch request
111114 self.startedTime = CFAbsoluteTimeGetCurrent ();
112115 self.prefetchURLs = urls;
113116 self.completionBlock = completionBlock;
117+ self.progressBlock = progressBlock;
114118
115119 // Starts prefetching from the very first image on the list with the max allowed concurrency
116120 NSUInteger listCount = self.prefetchURLs .count ;
0 commit comments