Skip to content

Commit

Permalink
ASNetworkImageNode ARC fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
secretiverhyme committed Nov 22, 2014
1 parent 964d109 commit 03156dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions AsyncDisplayKit/ASNetworkImageNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
/**
* The delegate, which must conform to the <ASNetworkImageNodeDelegate> protocol.
*/
@property (atomic, assign, readwrite) id<ASNetworkImageNodeDelegate> delegate;
@property (atomic, weak, readwrite) id<ASNetworkImageNodeDelegate> delegate;

/**
* A placeholder image to display while the URL is loading.
*/
@property (atomic, retain, readwrite) UIImage *defaultImage;
@property (atomic, strong, readwrite) UIImage *defaultImage;

/**
* The URL of a new image to download and display.
*
* @discussion Changing this property will reset the displayed image to a placeholder (<defaultImage>) while loading.
*/
@property (atomic, retain, readwrite) NSURL *URL;
@property (atomic, strong, readwrite) NSURL *URL;

/**
* Download and display a new image.
Expand Down
22 changes: 12 additions & 10 deletions AsyncDisplayKit/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,28 @@ - (void)_lazilyLoadImageIfNecessary
});
}
} else {
// The delegate must be retained, as nothing prevents it from being deallocated during the delay before completionBlock is executed.
// Clients (the delegate) /should/ set our delegate property to nil in their -dealloc, but don't always do this.
__block id<ASNetworkImageNodeDelegate> delegate = _delegate;

__weak __typeof__(self) weakSelf = self;
void (^finished)(CGImageRef) = ^(CGImageRef responseImage) {
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}

{
ASDN::MutexLocker l(_lock);
ASDN::MutexLocker l(strongSelf->_lock);

if (responseImage != NULL) {
_imageLoaded = YES;
self.image = [UIImage imageWithCGImage:responseImage];
strongSelf->_imageLoaded = YES;
strongSelf.image = [UIImage imageWithCGImage:responseImage];
}

_imageDownload = nil;
strongSelf->_imageDownload = nil;

_cacheUUID = nil;
strongSelf->_cacheUUID = nil;
}

if (responseImage != NULL) {
[delegate imageNode:self didLoadImage:self.image];
[strongSelf->_delegate imageNode:self didLoadImage:self.image];
}
};

Expand Down

0 comments on commit 03156dc

Please sign in to comment.