Subject: Swift 4 Programming Language

Variable Declaration

  • 3 weeks ago
    bruce bookman
    In swift, declare a variable like this var thisVariable: Int The above variable name is 'thisVariable' and it is marked as a variable with a value type of Integer.
  • 3 weeks ago
    bruce bookman
    Swift constants are declared like this let thisConstant: Int The above constant is 'thisConstant'. The "let" keyword makes it a constant rather than a variable. This constant has an Integer type
  • 3 weeks ago
    bruce bookman
    Swift constants and variable can be set to a value. For example let thisEqualsEight: Int = 8 The above sets the variable "thisEqualsEight" to the value of '8'. Also the variable 'thisEqualsEight' is declared as an Integer type. var thisStringIsHello: String = "Hello" The above sets the variable named "thisStringIsHello" to the value "Hello". It is also declared as a type String
  • 3 weeks ago
    bruce bookman
    Swift variables and constants can have no value. This does not mean zero, this means empty. It is represented by the keyword "nil" Examples: let thisConstantHasNoValue: Int = nil var thisVariableHasNoValue: Int = nil