I have the following code:
- (void)downloadPressed:(id)sender {
[_download startDownloadWithParser:^id(NSData *rawData) {
NSString* downloadName = [[_download url] lastPathComponent];
// ... more code
}];
[self reloadView];
}
This code is located inside a UITableViewCell, and as we all know, the reuse mechanism should be taken very special note of..
My Question, Clean & Simple:
If I add the following line of code after the block:
_download = nil;
The _download variable inside the block also gets nil’d! I would like it to get a copy instead, how?
If you would like your block to get a copy of your ivar, make a local variable from it, and use that local inside your block instead of the ivar:
The block will capture the value of that local variable at the time the block object is created, making all subsequent changes to
_downloadinvisible to your block.