99//
1010
1111#import " ASNetworkImageNode.h"
12+ #import " ASImageNode+Private.h"
1213
1314#import " ASBasicImageDownloader.h"
1415#import " ASDisplayNodeInternal.h"
16+ #import " ASDisplayNodeExtras.h"
1517#import " ASDisplayNode+Subclasses.h"
1618#import " ASDisplayNode+FrameworkPrivate.h"
1719#import " ASEqualityHelpers.h"
1820#import " ASInternalHelpers.h"
1921#import " ASImageContainerProtocolCategories.h"
20- #import " ASDisplayNodeExtras.h"
2122
2223#if PIN_REMOTE_IMAGE
2324#import " ASPINRemoteImageDownloader.h"
@@ -67,6 +68,7 @@ @interface ASNetworkImageNode ()
6768 unsigned int cacheSupportsSynchronousFetch:1 ;
6869 } _cacheFlags;
6970}
71+
7072@end
7173
7274@implementation ASNetworkImageNode
@@ -116,6 +118,12 @@ - (void)dealloc
116118
117119#pragma mark - Public methods -- must lock
118120
121+ - (void )setImage : (UIImage *)image
122+ {
123+ ASDisplayNodeAssert (NO , @" Setting the image directly to an ASNetworkImageNode is not allowed. Please either use the defaultImage property or move to an ASImageNode" );
124+ [self __setImage: image];
125+ }
126+
119127- (void )setURL : (NSURL *)URL
120128{
121129 [self setURL: URL resetToDefault: YES ];
@@ -136,7 +144,7 @@ - (void)setURL:(NSURL *)URL resetToDefault:(BOOL)reset
136144
137145 BOOL hasURL = _URL == nil ;
138146 if (reset || hasURL) {
139- self. image = _defaultImage;
147+ [ self __setImage: _defaultImage] ;
140148 /* We want to maintain the order that currentImageQuality is set regardless of the calling thread,
141149 so always use a dispatch_async to ensure that we queue the operations in the correct order.
142150 (see comment in displayDidFinish) */
@@ -171,7 +179,7 @@ - (void)setDefaultImage:(UIImage *)defaultImage
171179 dispatch_async (dispatch_get_main_queue (), ^{
172180 self.currentImageQuality = hasURL ? 0.0 : 1.0 ;
173181 });
174- self. image = defaultImage;
182+ [ self __setImage: defaultImage] ;
175183 }
176184}
177185
@@ -256,7 +264,7 @@ - (void)displayWillStartAsynchronously:(BOOL)asynchronously
256264 if (_imageLoaded == NO && _URL && _downloadIdentifier == nil ) {
257265 UIImage *result = [[_cache synchronouslyFetchedCachedImageWithURL: _URL] asdk_image ];
258266 if (result) {
259- self. image = result;
267+ [ self __setImage: result] ;
260268 _imageLoaded = YES ;
261269 dispatch_async (dispatch_get_main_queue (), ^{
262270 _currentImageQuality = 1.0 ;
@@ -340,7 +348,7 @@ - (void)handleProgressImage:(UIImage *)progressImage progress:(CGFloat)progress
340348 if (ASObjectIsEqual (_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil ) {
341349 return ;
342350 }
343- self. image = progressImage;
351+ [ self __setImage: progressImage] ;
344352 dispatch_async (dispatch_get_main_queue (), ^{
345353 // See comment in -displayDidFinish for why this must be dispatched to main
346354 self.currentImageQuality = progress;
@@ -396,7 +404,7 @@ - (void)_clearImage
396404 ASPerformBackgroundDeallocation (image);
397405 }
398406 self.animatedImage = nil ;
399- self. image = _defaultImage;
407+ [ self __setImage: _defaultImage] ;
400408 _imageLoaded = NO ;
401409 // See comment in -displayDidFinish for why this must be dispatched to main
402410 dispatch_async (dispatch_get_main_queue (), ^{
@@ -456,7 +464,7 @@ - (void)_lazilyLoadImageIfNecessary
456464
457465 dispatch_async (dispatch_get_main_queue (), ^{
458466 if (self.shouldCacheImage ) {
459- self. image = [UIImage imageNamed: _URL.path.lastPathComponent];
467+ [ self __setImage: [UIImage imageNamed: _URL.path.lastPathComponent] ];
460468 } else {
461469 // First try to load the path directly, for efficiency assuming a developer who
462470 // doesn't want caching is trying to be as minimal as possible.
@@ -486,7 +494,7 @@ - (void)_lazilyLoadImageIfNecessary
486494 if (animatedImage != nil ) {
487495 self.animatedImage = animatedImage;
488496 } else {
489- self. image = nonAnimatedImage;
497+ [ self __setImage: nonAnimatedImage] ;
490498 }
491499 }
492500
@@ -522,7 +530,7 @@ - (void)_lazilyLoadImageIfNecessary
522530 if ([imageContainer asdk_animatedImageData ] && _downloaderFlags.downloaderImplementsAnimatedImage ) {
523531 strongSelf.animatedImage = [_downloader animatedImageWithData: [imageContainer asdk_animatedImageData ]];
524532 } else {
525- strongSelf. image = [imageContainer asdk_image ];
533+ [ strongSelf __setImage: [imageContainer asdk_image ] ];
526534 }
527535 dispatch_async (dispatch_get_main_queue (), ^{
528536 strongSelf->_currentImageQuality = 1.0 ;
0 commit comments