Skip to content

Commit 2ad8d81

Browse files
author
Olivier Poitrey
committed
Merge pull request SDWebImage#634 from burakkilic/patch-1
Update SDWebImagePrefetecher.m
2 parents 895249b + 159f082 commit 2ad8d81

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

SDWebImage/SDWebImagePrefetcher.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)