Authored by Olivier Poitrey

Merge pull request #700 from herrernst/master

Save image in cache before calling completion block
@@ -162,24 +162,24 @@ @@ -162,24 +162,24 @@
162 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 162 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
163 UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; 163 UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
164 164
165 - dispatch_main_sync_safe(^{  
166 - completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished);  
167 - });  
168 -  
169 if (transformedImage && finished) { 165 if (transformedImage && finished) {
170 BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage]; 166 BOOL imageWasTransformed = ![transformedImage isEqual:downloadedImage];
171 [self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:data forKey:key toDisk:cacheOnDisk]; 167 [self.imageCache storeImage:transformedImage recalculateFromImage:imageWasTransformed imageData:data forKey:key toDisk:cacheOnDisk];
172 } 168 }
  169 +
  170 + dispatch_main_sync_safe(^{
  171 + completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished);
  172 + });
173 }); 173 });
174 } 174 }
175 else { 175 else {
176 - dispatch_main_sync_safe(^{  
177 - completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished);  
178 - });  
179 -  
180 if (downloadedImage && finished) { 176 if (downloadedImage && finished) {
181 [self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk]; 177 [self.imageCache storeImage:downloadedImage recalculateFromImage:NO imageData:data forKey:key toDisk:cacheOnDisk];
182 } 178 }
  179 +
  180 + dispatch_main_sync_safe(^{
  181 + completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished);
  182 + });
183 } 183 }
184 } 184 }
185 185