@@ -17,6 +17,7 @@ @interface SDWebImagePrefetcher ()
17
17
@property (assign , nonatomic ) NSUInteger skippedCount;
18
18
@property (assign , nonatomic ) NSUInteger finishedCount;
19
19
@property (assign , nonatomic ) NSTimeInterval startedTime;
20
+ @property (SDDispatchQueueSetterSementics, nonatomic ) void (^completionBlock)(NSUInteger , NSUInteger );
20
21
21
22
@end
22
23
@@ -79,6 +80,11 @@ - (void)startPrefetchingAtIndex:(NSUInteger)index
79
80
else if (self.finishedCount == self.requestedCount )
80
81
{
81
82
[self reportStatus ];
83
+ if (self.completionBlock )
84
+ {
85
+ self.completionBlock (self.finishedCount , self.skippedCount );
86
+ self.completionBlock = nil ;
87
+ }
82
88
}
83
89
}];
84
90
}
@@ -90,10 +96,16 @@ - (void)reportStatus
90
96
}
91
97
92
98
- (void )prefetchURLs : (NSArray *)urls
99
+ {
100
+ [self prefetchURLs: urls completed: nil ];
101
+ }
102
+
103
+ - (void )prefetchURLs : (NSArray *)urls completed : (void (^)(NSUInteger , NSUInteger ))completionBlock
93
104
{
94
105
[self cancelPrefetching ]; // Prevent duplicate prefetch request
95
106
self.startedTime = CFAbsoluteTimeGetCurrent ();
96
107
self.prefetchURLs = urls;
108
+ self.completionBlock = completionBlock;
97
109
98
110
// Starts prefetching from the very first image on the list with the max allowed concurrency
99
111
NSUInteger listCount = self.prefetchURLs .count ;
0 commit comments