Swift iOS - 如何修复 If 语句构建时警告中的嵌套变量

Swift iOS - How should one fix nested variables in If statement buildtime warnings

例如,我看到以下代码的警告:

  var currentButtonLocation = self.view.frame
    if let button = view.viewWithTag(11) as? UIButton {
        currentButtonLocation = button.frame
    }

产生以下错误:

 Variable 'currentButtonLocation' was written to, but never read

警告相当self-explanatory,只是因为你从来没有使用过currentButtonLocation

例如,这样做会使警告消失:

let newButtonFrame = currentButtonLocation

一般来说,您不应该使用您实际上不会阅读的变量(或与此相关的常量)。