From 98082a679192c46b246d8d650f3be31e0d4b2e94 Mon Sep 17 00:00:00 2001 From: Alexis Creuzot Date: Tue, 14 Oct 2014 11:16:58 +0200 Subject: [PATCH] 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) --- SDWebImage/SDWebImagePrefetcher.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/SDWebImage/SDWebImagePrefetcher.m b/SDWebImage/SDWebImagePrefetcher.m index 6c5f9533..7855eea4 100644 --- a/SDWebImage/SDWebImagePrefetcher.m +++ b/SDWebImage/SDWebImagePrefetcher.m @@ -120,10 +120,16 @@ self.completionBlock = completionBlock; self.progressBlock = progressBlock; - // Starts prefetching from the very first image on the list with the max allowed concurrency - NSUInteger listCount = self.prefetchURLs.count; - for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { - [self startPrefetchingAtIndex:i]; + if(urls.count == 0){ + if(completionBlock){ + completionBlock(0,0); + } + }else{ + // Starts prefetching from the very first image on the list with the max allowed concurrency + NSUInteger listCount = self.prefetchURLs.count; + for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { + [self startPrefetchingAtIndex:i]; + } } }