better completion block handling

make sure to remove the completion block once done.
This should help in cases the user forgot to do the weak-dance
as well as when the copied objects are release
This commit is contained in:
Stephan Diederich 2013-08-15 22:31:53 +02:00
parent ff555cb87d
commit c39053dbd2

View File

@ -93,15 +93,16 @@
}
- (void)setCompletion:(BITNetworkCompletionBlock)completion {
__weak typeof(self) weakSelf = self;
if(nil == completion) {
if(!completion) {
[super setCompletionBlock:nil];
} else {
__weak typeof(self) weakSelf = self;
[super setCompletionBlock:^{
typeof(self) strongSelf = weakSelf;
if(strongSelf) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(strongSelf, strongSelf->_data, strongSelf->_error);
[strongSelf setCompletionBlock:nil];
});
}
}];