var aVariable = 0 let aConstant = 0
var aString: String var aBool: Bool var aInt: Int var aDouble: Double
var bString = "A String!" var bBool = true var bInt = 3 var bDouble = 3.0
var cDouble: Double = 3
var dDouble = Double(3)
var score = 0 { willSet { // Score will be updated } didSet { // Score was updated } }
var message = "You scored\(score)"
var emptyArray: [String] = [] var arrayOfInts = [3, 1, 2, 5] arrayOfInts.append(4)
var emptyDictionary: [String: String] = [:] var dict = ["A": 1, "B": 2, "C": 3] dict["D"] = 4
var emptySet: Set<String> = [] //empty Set var setOfStrings: Set = ["A", "B", "C"] setOfStrings.insert("D")
let closedRange = 1...3 // include 3 let halfOpenRange = 1..<3 // exclude 3
for index in 1...3 { print("\(index) banana") }
let distances = [3, 1, 2, 5, 4] var returnDistances: [Int] = [] for distance in distances { returnDistances.append(distance * 2) }
print(distances.map( { $0 * 2 } )) // [6,2,4,10,8] print(distances.filter( { $0 >= 3 } )) // [3,5,4] print(distances.reduce(0, {$0 + $1} )) // 15 print(distances.sorted(by: { $0 > $1 } )) // [5,4,3,2,1]
var card1: (Int, String) card1 = (7, "♥") card1.0 = 3 print("\(card1.0) of \(card1.1)") // The 3 of ♥
enum AEnum { case aCase case bCase } let aEnum = AEnum.bCase
func aFunc() { // Do something }