Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Non-optional vars
var mutableBeverage = "Leffe"
println(mutableBeverage) // "Leffe"
mutableBeverage = "Bud"
println(mutableBeverage) // "Bud"
mutableBeverage = mutableBeverage + "weiser"
println(mutableBeverage) // "Budweiser"
mutableBeverage = nil // Compiler error
// Optional vars
var mutableCostume: String? = "Dracula"
println(mutableCostume) // Optional("Dracula")
mutableCostume = "Frankenstein"
println(mutableCostume) // Optional("Frankenstein")
mutableCostume = "Bride of " + mutableCostume!
println(mutableCostume) // Optional("Bride of Frankenstein")
mutableCostume = nil // nil
// Non-optional lets
let immutableBeverage = "Bud"
println(immutableBeverage) // "Bud"
immutableBeverage = "Leffe" // Compiler error
immutableBeverage = immutableBeverage + "weiser" // Compiler error
immutableBeverage = nil // Compiler error
// Optional lets
let immutableCostume: String? = "Dracula"
println(immutableCostume) // Optional("Dracula")
immutableCostume = "Frankenstein" // Compiler error
immutableCostume = "Bride of " + immutableName! // Compiler error
immutableCostume = nil // Compiler error
let anotherCostume: String? = nil
println(anotherCostume) // nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment