Swift Vriables and Constants

Variable Declaration

You must declare variable using var keyword. it's values can be modified after their definition.

var variableName = <initial value>

The following example shows how to declare a variable in Swift 4

var varA = 42
print(varA)

we get the following result 

42

Type Annotations with variable

You can provide a type annotation when you declare a variable, to be clear about the kind of values the variable can store

var variableName:<data type> = <optional initial value>
Examples:
var varA = 42
print(varA)

var varB:Float
varB = 3.14159
print(varB)

Result:

42
3.1415901184082

Constants Declaration

You must declare constant using let keyword. it's values cannot be modified after their definition.

let constantName = <initial value>

example:

let constA = 42
print(constA)

Result:

42