Learn to Code Special! | 30% off ALL ACCESS to One Month ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

Hide

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: https://github.com/onemonth/one-month-ios

Play in your first playground

MyPlayground.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"]
myOtherArray.append("one")
myOtherArray.append("two")

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

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

myOtherDictionary