I need to retain a variable inside a block because i have to pass it to a method out of the block. I dont know how to achieve this.
__weak MyClass *weakSelf = self;
[myFile addObserver:self block:^
{
if ([[[weakSelf myFile] newerStatus] cached] )
{
[weakSelf performSelector:@selector(myMethod:) withObject:weakSelf.myFile afterDelay:5];
}
}];
I tried also doing this but no success:
__block DBFile *myFileFinal;
__weak MyClass *weakSelf = self;
[myFile addObserver:self block:^
{
if ([[[weakSelf myFile] newerStatus] cached] )
{
__strong MyClass *strongSelf = weakSelf;
myFileFinal = strongSelf.myFile;
[weakSelf performSelector:@selector(myMethod:) withObject:myFileFinal afterDelay:5];
}
}];
How can i retain "myFile" for use outside of the block? Need help please. Thanks in advance.
I don't know what you mean by "How can i retain "myFile" for use outside of the block?"
performSelector:withObject:afterDelay:
retains the receiver and arguments until the action is performed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.