@@ -27,6 +27,7 @@ @interface FICImageCache () {
2727 NSMutableDictionary *_requests;
2828 __weak id <FICImageCacheDelegate> _delegate;
2929
30+ BOOL _delegateImplementsWantsSourceImageForEntityWithFormatNameCompletionBlock;
3031 BOOL _delegateImplementsShouldProcessAllFormatsInFamilyForEntity;
3132 BOOL _delegateImplementsErrorDidOccurWithMessage;
3233 BOOL _delegateImplementsCancelImageLoadingForEntityWithFormatName;
@@ -46,6 +47,7 @@ - (void)setDelegate:(id<FICImageCacheDelegate>)delegate {
4647 if (delegate != _delegate) {
4748 _delegate = delegate;
4849
50+ _delegateImplementsWantsSourceImageForEntityWithFormatNameCompletionBlock = [_delegate respondsToSelector: @selector (imageCache:wantsSourceImageForEntity:withFormatName:completionBlock: )];
4951 _delegateImplementsShouldProcessAllFormatsInFamilyForEntity = [_delegate respondsToSelector: @selector (imageCache:shouldProcessAllFormatsInFamily:forEntity: )];
5052 _delegateImplementsErrorDidOccurWithMessage = [_delegate respondsToSelector: @selector (imageCache:errorDidOccurWithMessage: )];
5153 _delegateImplementsCancelImageLoadingForEntityWithFormatName = [_delegate respondsToSelector: @selector (imageCache:cancelImageLoadingForEntity:withFormatName: )];
@@ -187,7 +189,7 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
187189 }
188190 };
189191
190- if (image == nil && _delegate != nil ) {
192+ if (image == nil ) {
191193 // No image for this UUID exists in the image table. We'll need to ask the delegate to retrieve the source asset.
192194 NSURL *sourceImageURL = [entity sourceImageURLWithFormatName: formatName];
193195
@@ -200,9 +202,19 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
200202 [_requests setObject: requestDictionary forKey: sourceImageURL];
201203
202204 _FICAddCompletionBlockForEntity (formatName, requestDictionary, entity, completionBlock);
203- [_delegate imageCache: self wantsSourceImageForEntity: entity withFormatName: formatName completionBlock: ^(UIImage *sourceImage) {
205+ UIImage *image;
206+ if ([entity respondsToSelector: @selector (imageForFormat: )]){
207+ FICImageFormat *format = [self formatWithName: formatName];
208+ image = [entity imageForFormat: format];
209+ }
210+
211+ if (image){
212+ [self _imageDidLoad: image forURL: sourceImageURL];
213+ } else if (_delegateImplementsWantsSourceImageForEntityWithFormatNameCompletionBlock){
214+ [_delegate imageCache: self wantsSourceImageForEntity: entity withFormatName: formatName completionBlock: ^(UIImage *sourceImage) {
204215 [self _imageDidLoad: sourceImage forURL: sourceImageURL];
205- }];
216+ }];
217+ }
206218 } else {
207219 // We have an existing request dictionary, which means this URL is currently being fetched.
208220 _FICAddCompletionBlockForEntity (formatName, requestDictionary, entity, completionBlock);
0 commit comments