In ReactiveCocoa there is macro to prevent retain cycle @weakify
and @strongify. From my understanding @weakify
do something like what I usually do that is create __weak
reference for using in the block, but what about @strongify
?
Why do I need to make it strong again in the block?
Here is some sample usage:
@weakify(self);
[RACObserve(self, username) subscribeNext:^(NSString *username) {
@strongify(self);
[self validateUsername];
}];
If you just use a weak reference within the block, self can get deallocated while the block is being executed. But if you want to ensure that self stays in memory until the block finishes execution, you have to convert the weak reference back to strong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With