我做的强孰弱舞蹈SWIFT是这样的:斯威夫特后卫自
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), { [weak self] in
guard let `self` = self else {
return
}
self.doSomething(1)
})
在此之前,我用的是strongSelf
,而不是`self`。在一个网站上我已经看到我可以使用这个字符。
但是这个角色在Swift中做了什么?没有这个我不能分配给自己。为什么这个工作?使用它是一个好习惯吗?
相关:http://stackoverflow.com/questions/31315358/use-reserved-keyword-a-enum-case。 –
在未来版本的Swift中有一个建议允许'guard let self = self else {return}':https://github.com/apple/swift-evolution/blob/master/proposals/0079-upgrade-self -from-weak-to-strong.md,而且你的代码工作被认为是Swift编译器中的一个错误:https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160118/007425 html的。 –