我对在块内使用 self 感到困惑,我浏览了一些 Apple 的文档,但仍然找不到正确的答案。
有些人总是说在块中使用弱自我,但有些人说在复制的块中使用弱自我,而不是总是使用。
样品 1:
self.handler = ^(id response, NSError *error)
{
self.newresponse = response; //use weak self here
};
样本 2:
使用弱自我;
__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