【发布时间】:2020-04-16 07:50:44
【问题描述】:
有人可以向我解释一下这段代码中 self = self 的目的是什么吗?
// Keep the reference to the interface :
private var guidedItfRef: Ref<GuidedPilotingItf>?
private var goUp: Bool
...
guidedItfRef = provider.getPilotingItf(PilotingItfs.guided) { [weak self] guidedItf in
if let guidedItf = guidedItf, let self = self, guidedItf.currentDirective == nil {
self.goUp = !self.goUp
guidedItf.moveToRelativePosition(forwardComponent: 0, rightComponent: 0,
downwardComponent: self.goUp ? 2.0 : -3.0 , headingRotation: 0)
}
}
【问题讨论】:
-
建议:如果使用较新版本的 Swift,请将
self.goUp = !self.goUp替换为self.goUp.toggle()。
标签: swift