Vars, vars, all types of vars

Introduction to Swift · Lesson 5 · 14 minutes

What's a var? What sorts of vars do we see in Swift?

All of the code that we write in this section and the others is open source and available here in its entirety:

For additional information on vars, lets and optionals check out Optionals for Beginners.

Play in your first playground


//: Playground - noun: a place where people can play

import UIKit

var myString = "Hello, playground"

var myOtherString: String
myOtherString = "something cool"

var myInt = 1000
myInt = myInt * 5

var myOtherInt: Int
myOtherInt = 999

var myFloat = 0.5
var myOtherFloat = 0.9999
myOtherFloat = 1.02

var myArray = ["something"]

var myOtherArray: Array<String>
myOtherArray = ["zero"]

var myDictionary = ["key" : "value"]

var myOtherDictionary: Dictionary<String, String>
myOtherDictionary = ["one" : "value1"]
myOtherDictionary["two"] = "value2"