Enforced presence of a completedBlock in downloadWithURL:options:progress:completed:

This method bails out in case of a missing `completedBlock`. While this makes sense (downloading the image without a completion block and not doing anything with it is pointless), a client passing a empty block is not informed about the mistake.

`NSParameterAssert` validates the input and it informs the client about bad usage of the API.
This commit is contained in:
Gabriele Petronella 2013-08-29 12:46:15 +01:00
parent 22cd4e49c4
commit f37474d5c8
1 changed files with 6 additions and 6 deletions

View File

@ -68,6 +68,9 @@
- (id<SDWebImageOperation>)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;
}