The nil coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil.
12345
letdefaultColorName="red"varuserDefinedColorName:String?// defaults to nilvarcolorNameToUse=userDefinedColorName??defaultColorName// userDefinedColorName is nil, so colorNameToUse is set to the default of "red"
Range Operators
12345678
forindexin1...5{println("\(index) times 5 is \(index * 5)")}// 1 times 5 is 5// 2 times 5 is 10// 3 times 5 is 15// 4 times 5 is 20// 5 times 5 is 25
Half-Open Range Operator
123456789
letnames=["Anna","Alex","Brian","Jack"]letcount=names.countforiin0..<count{println("Person \(i + 1) is called \(names[i])")}// Person 1 is called Anna// Person 2 is called Alex// Person 3 is called Brian// Person 4 is called Jack>