What is the difference between `let` and `var` in swift?

后端 未结 30 1326
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 11:09

What is the difference between let and var in Apple\'s Swift language?

In my understanding, it is a compiled language but it does not check

30条回答
  •  萌比男神i
    2020-11-22 12:02

    The

    Declaring Constants and Variables section of The Swift Programming Language documentation specifies the following:

    You declare constants with the let keyword and variables with the var keyword.

    Make sure to understand how this works for Reference types. Unlike Value Types, the object's underlying properties can change despite an instance of a reference type being declared as a constant. See the Classes are Reference Types section of the documentation, and look at the example where they change the frameRate property.

提交回复
热议问题