I went through some of these articles about ARC in OBJ-C (https://dhoerl.wordpress.com/2013/04/23/i-finally-figured-out-weakself-and-strongself/, http://tech.pro/tutorial/1227/blocks-gcd-and-pitfalls-to-avoid, Always pass weak reference of self into block in ARC?), however these things are still unclear to me:
- (NSArray *)rightButtons{
__typeof(self) __weak weakSelf = self;
JAActionButton *button1 = [JAActionButton actionButtonWithTitle:@"Archive" color:kArchiveButtonColor handler:^(UIButton *actionButton, JASwipeCell*cell) {
[cell completePinToTopViewAnimation];
[weakSelf rightMostButtonSwipeCompleted:cell];
}];
return @[button1];
}
button1
is inside the lexical scope of rightButtons
method. It is not a property on this class. WHY do I need to pass weakSelf to the block then? Does the compiler see button1
as self.button1
(which would then make sense to use weakSelf within the block)? How does self retain this block so that you need weakSelf?
weakSelf
inside the block? You shouldn't in this case. Did you try it without the weak reference? Are there any problems (such as a reference cycle)? – rmaddy