Declare a variable


I want to declare a new variable (Integer, String, Array, Dictionary) and/or assign it an initial value.


// This is an Integer variable
var a : Int

// This is a String variable, initialized
var b : String = "My string"

// This is an Integer variable - no need to declare a type,
// since it's inferred from the right-hand side value
var c = 2

// An Array variable
var d = [1,2,3]

// Another array - also declaring the type
var e : [String] = ["one","two","three"]

// A Dictionary
var f = ["name": "John", "surname": "Doe"]

// An empty Dictionary
var g : [String:String] = [:]



Find answers here

Hi there! Ask Us a Question We are ready to help