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

后端 未结 30 1455
隐瞒了意图╮
隐瞒了意图╮ 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 11:41

    Declare constants with the let keyword and variables with the var keyword.

    let maximumNumberOfLoginAttempts = 10 var currentLoginAttempt = 0   
    let maximumNumberOfLoginAttempts = 10
    var currentLoginAttempt = 0
    

    Declare multiple constants or multiple variables on a single line, separated by commas:

    var x = 0.0, y = 0.0, z = 0.0
    

    Printing Constants and Variables

    You can print the current value of a constant or variable with the println function:

    println(friendlyWelcome)
    

    Swift uses string interpolation to include the name of a constant or variable as a placeholder in a longer string

    Wrap the name in parentheses and escape it with a backslash before the opening parenthesis:

    println("The current value of friendlyWelcome is \(friendlyWelcome)")
    

    Reference : http://iosswift.com.au/?p=17

提交回复
热议问题