为什么新 Xcode 版本给出关于在块内使用 self 的警告
Why new Xcode versions gives a warning about using self inside a block
为什么新 Xcode 版本给出关于在块内使用 self 的警告。
警告:
Block implicitly retains 'self'; explicitly mention 'self' to indicate
this is intended behavior
@interface ViewController : UIViewController {
NSString *myString;
}
当我们在变量名前加上 self->
.
时警告隐藏
我在rmaddy的answer
中读到直接调用变量和self->没有区别
这实际上是一个很好的警告,所以我可以看到他们在翻旗。通常情况下,人们会不小心将 self 保留在块中,从而形成保留循环。此警告通知您开发人员您可能会发生保留周期。
基本上,如果你看到 self
就知道该块正在保留它,如果你没有看到 self
,乍一看你可能会倾向于认为你正在使用局部变量。
为什么新 Xcode 版本给出关于在块内使用 self 的警告。
警告:
Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
@interface ViewController : UIViewController {
NSString *myString;
}
当我们在变量名前加上 self->
.
我在rmaddy的answer
中读到直接调用变量和self->没有区别这实际上是一个很好的警告,所以我可以看到他们在翻旗。通常情况下,人们会不小心将 self 保留在块中,从而形成保留循环。此警告通知您开发人员您可能会发生保留周期。
基本上,如果你看到 self
就知道该块正在保留它,如果你没有看到 self
,乍一看你可能会倾向于认为你正在使用局部变量。