ASNetworkImageNode ARC fixes.

This commit is contained in:
Nadine Salter
2014-11-21 14:01:23 -08:00
parent 964d109be6
commit 03156dceb6
2 changed files with 15 additions and 13 deletions

View File

@@ -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.

View File

@@ -191,26 +191,28 @@
});
}
} 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];
}
};