I am getting confused with use of self inside blocks, I go through some of Apple's documents but still cannot find the right answer.
Some people always say use weak self inside blocks, but some say use weak self in blocks that are copied, not neassary to use always.
Sample 1:
self.handler = ^(id response, NSError *error)
{
self.newresponse = response; //use weak self here
};
Sample 2:
Using weak self;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[weakSelf.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
//in above is it use of weak is neassary
}
completion:^(BOOL finished)
{
}];
Without weak self;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[myViewController.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
}
completion:^(BOOL finished)
{
}];
In the above samples, which are correct…?
**I am using ARC
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…