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

后端 未结 30 1487
隐瞒了意图╮
隐瞒了意图╮ 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条回答
  •  甜味超标
    2020-11-22 12:00

    Very simple:

    • let is constant.
    • var is dynamic.

    Bit of description:

    let creates a constant. (sort of like an NSString). You can't change its value once you have set it. You can still add it to other things and create new variables though.

    var creates a variable. (sort of like NSMutableString) so you can change the value of it. But this has been answered several times.

提交回复
热议问题