Skip to content

Commit 5ad370d

Browse files
author
Michael Shannon Potter
committed
Merge pull request #49 from chilldotcom/master
Always call completion blocks even when image fetched is nil
2 parents f711496 + 213a3ff commit 5ad370d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

FastImageCache/FICImageCache.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,23 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
223223

224224
- (void)_imageDidLoad:(UIImage *)image forURL:(NSURL *)URL {
225225
NSDictionary *requestDictionary = [_requests objectForKey:URL];
226-
if (image != nil && requestDictionary != nil) {
226+
if (requestDictionary != nil) {
227227
for (NSMutableDictionary *entityDictionary in [requestDictionary allValues]) {
228228
id <FICEntity> entity = [entityDictionary objectForKey:FICImageCacheEntityKey];
229229
NSString *formatName = [entityDictionary objectForKey:FICImageCacheFormatKey];
230230
NSDictionary *completionBlocksDictionary = [entityDictionary objectForKey:FICImageCacheCompletionBlocksKey];
231-
[self _processImage:image forEntity:entity withFormatName:formatName completionBlocksDictionary:completionBlocksDictionary];
231+
if (image != nil){
232+
[self _processImage:image forEntity:entity withFormatName:formatName completionBlocksDictionary:completionBlocksDictionary];
233+
} else {
234+
NSArray *completionBlocks = [completionBlocksDictionary objectForKey:formatName];
235+
if (completionBlocks != nil) {
236+
dispatch_async(dispatch_get_main_queue(), ^{
237+
for (FICImageCacheCompletionBlock completionBlock in completionBlocks) {
238+
completionBlock(entity, formatName, nil);
239+
}
240+
});
241+
}
242+
}
232243
}
233244
}
234245

0 commit comments

Comments
 (0)