diff --git a/SDWebImage/SDWebImageManager.h b/SDWebImage/SDWebImageManager.h index 736fbba8..da8abcec 100644 --- a/SDWebImage/SDWebImageManager.h +++ b/SDWebImage/SDWebImageManager.h @@ -142,7 +142,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; * @param progressBlock A block called while image is downloading * @param completedBlock A block called when operation has been completed. * - * This block as no return value and takes the requested UIImage as first parameter. + * This parameter is required. + * + * This block has no return value and takes the requested UIImage as first parameter. * In case of error the image parameter is nil and the second parameter may contain an NSError. * * The third parameter is an `SDImageCacheType` enum indicating if the image was retrived from the local cache diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 7e241377..8940d656 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -68,6 +68,9 @@ - (id)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock { + // Invoking this method without a completedBlock is pointless + NSParameterAssert(completedBlock); + // Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't // throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString. if ([url isKindOfClass:NSString.class]) @@ -90,16 +93,13 @@ isFailedUrl = [self.failedURLs containsObject:url]; } - if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && isFailedUrl)) + if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { - if (completedBlock) + dispatch_main_sync_safe(^ { - dispatch_main_sync_safe(^ - { NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]; completedBlock(nil, error, SDImageCacheTypeNone, YES); - }); - } + }); return operation; }