【发布时间】:2021-05-02 08:12:24
【问题描述】:
让我们调用一些函数,它有一个转义闭包作为参数:
someFunc(complition: {
self.someAnotherFunc()
})
相当于:
someFunc(complition: { [self] in
someAnotherFunc()
})
相当于:
someFunc(someAnotherFunc)
正确吗?
我认为那是正确的。self 在上方强烈捕获。
那么 [weak self] 的情况呢?
是我们唯一可以写的方法吗?:
someFunc(complition: { [weak self] in
self?.someAnotherFunc()
})
我们就不能写成someFunc(someAnotherFunc)吗?
附:好吧,我知道还有另外一种写法:
someFunc { [weak self] in
self?.someAnotherFunc()
}
但是更简洁的形式呢?
【问题讨论】:
标签: swift syntax closures swift5