School's Out for Summer Sale! — 50% off all courses at One Month

Video not found

Vars, Vars, All Types of Vars

Getting Started: Introduction to Swift · Lesson 4 ·

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:

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"