Skip to content

Commit 98082a6

Browse files
author
Alexis Creuzot
committed
Handle empty urls NSArray
In some cases the user may end up with an empty urls NSArray, in which case the completion block is never called. This commit handle such case to call immediately the completion block (if any)
1 parent 2233b5e commit 98082a6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

SDWebImage/SDWebImagePrefetcher.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,16 @@ - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock
120120
self.completionBlock = completionBlock;
121121
self.progressBlock = progressBlock;
122122

123-
// Starts prefetching from the very first image on the list with the max allowed concurrency
124-
NSUInteger listCount = self.prefetchURLs.count;
125-
for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
126-
[self startPrefetchingAtIndex:i];
123+
if(urls.count == 0){
124+
if(completionBlock){
125+
completionBlock(0,0);
126+
}
127+
}else{
128+
// Starts prefetching from the very first image on the list with the max allowed concurrency
129+
NSUInteger listCount = self.prefetchURLs.count;
130+
for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
131+
[self startPrefetchingAtIndex:i];
132+
}
127133
}
128134
}
129135

0 commit comments

Comments
 (0)