Episode #187

Swift 2 Basics

17 minutes
Published on September 17, 2015
In this episode we take a look at Swift 2's basic types such as Int, Double, Bool, Array, and Dictionary. This episode is part of a series covering Swift 2 from a beginner's perspective.

Episode Links

let x = 1 + 2
var y: Int
let z: Float = 5.5

let name = "Ben"
let msg = "Hello, \(name)."

print(name)

var items = [1, 2, 3]
items.append(4)
items.removeAtIndex(0)
items.insert(10, atIndex: 0)
let a = items[0]

var mixed: [Any] = [1, false, "a"]
let b = mixed[0] as! Int


let slice = items[1..<3]

for (index, item) in items.enumerate() {
    print("Item (\(index)): \(item)")
}


var menu = [
    "queso" : 4.50,
    "tacos" : 6.00,
    "enchiladas": 8.95,
    "fajitas": 21.00
]

menu["chips"] = 1.00
menu["chips"] = nil

for (item, price) in menu {
    print("\(item) costs \(price)")
}

let max = 10
for x in 0...max {
    let v = x - max/2
    v * v
}
Want more? Subscribers can view all 587 episodes. New episodes are released regularly.

Subscribe to get access →

Source Code

View on GitHub Download Source