Variable 'xxx' was never mutated, consider changing to 'let'

前端 未结 5 1093
北荒
北荒 2020-12-17 10:40

Updated to xcode7-beta I run across a new kind of warning. Here is my code

override func layoutAttributesForElementsInRect(rect: CGRect) -&g         


        
5条回答
  •  粉色の甜心
    2020-12-17 11:11

    By declaring a constant with let, you ensure that it can never be changed. This is good for making sure that you don't accidentally change it later, and it (in theory) can help the optimizer generate faster code.

    If you declare a variable with var, and you don't intend to change it or call mutating methods on it, using let instead helps you enforce that contract.

提交回复
热议问题