小编Гол*_*ген的帖子

什么是在swift中使用strongSelf的正确方法?

在非平凡块中的Objective-C中,我注意到了weakSelf/strongSelf的使用.

在Swift中使用strongSelf的正确方法是什么?就像是:

if let strongSelf = self {
  strongSelf.doSomething()
}
Run Code Online (Sandbox Code Playgroud)

因此,对于每个包含self的闭包,我应该添加strongSelf检查?

if let strongSelf = self {
  strongSelf.doSomething1()
}

if let strongSelf = self {
  strongSelf.doSomething2()
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让上述更优雅?

closures automatic-ref-counting swift

9
推荐指数
4
解决办法
5204
查看次数

标签 统计

automatic-ref-counting ×1

closures ×1

swift ×1