我在使用块内的 self 时感到困惑,我查阅了一些苹果文档,但仍然找不到正确答案。
有些人总是说在块内使用 weak self,但也有人说只有在复制的块中使用 weak self,不一定总是需要使用。
示例1:
self.handler = ^(id response, NSError *error)
{
self.newresponse = response; //use weak self here
};
示例2:
使用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)
{
}];
没有脆弱的自我;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[myViewController.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
}
completion:^(BOOL finished)
{
}];
在上面的样本中,哪些是正确的...? **我正在使用ARC