1. Swift is used to determine whether option is nil, which is equivalent to If (option) of OC)
If let name = option {greeting = "If ===="} else {greeting = "else = "}
2. After running the matching clause in the switch, the program exits the switch statement and does not continue to run downward. Therefore, you do not need to write break at the end of each clause.
3. // The range created by using... does not contain the upper limit. If you want to include it, you need to use.... The set is the relationship between [) and [].
For I in 0 .. 3 {println ("I ===\ (I)") // only goes through 0, 1, 2 three cycles}
4. // input array parameters
Func sumof (numbers: int...)-> int {var sum = 0 for number in numbers {sum + = number} return sum}
5. // function nesting. Define and use functions in the function.
Func returnfifteen ()-> int {var y = 10 func add () {Y + = 5} Add () return y}
6. When processing optional values of variables, you can add? Before operations (such as methods, attributes, and subscripts ?. If? The previous value is nil ,? All subsequent things are ignored, and the entire expression returns nil. Otherwise ,? All subsequent things will be run.
June 27, 2014