Import UIKit
Note : You can not write in Swift ; Number , but there is a certain precondition , a line only one sentence code
If a line has multiple lines of code, then ; Still have to write
Note : Swift is a perverted place , sometimes the operator's left and right if there is no space to write an error
Let num = ten
/*:
If
* If in Swift and if usage in OC is roughly the same , knowledge is slightly different in detail
Different points
* 1.OC Central Africa 0 is true , and there is no such concept in Swift, the conditional expression for if in Swift must be a bool value
* The true bool type is available in Swift, with a value of true/false
* the () of conditional expressions in 2.Swift can be omitted
* 3.OC If there is only one statement in the If , then {} can be omitted , but the Swift is not allowed to omit , even if only one can not
* If else/if else if the write is the same as OC
*/
If num = = Ten
{
Print(" is ten")
}
If num = = 5
{
Print("5")
}Else
{
Print("ten")
}
/*:
Trinocular operator
* The three-mesh operator in Swift is exactly the same as OC, except that the conditional expression can only be of type bool
* in Swift Development, the trinocular operator uses very much
*/
Let value = Ten
Let res = value = = ? : 0
/*:
Switch
* switch usage in Swift is roughly the same as in OC
Different points :
* The conditional expression () can be omitted
* in OC if the break after the case is omitted , Swift does not
* in OC if you want to define variables in case, You must add {}, otherwise the scope is confusing, and Swift does not
* the location of default in OC can be arbitrarily written , will be judged after all the case will execute default, and Swift Can not be randomly written in the last
* default can be omitted in OC , and most cases in Swift cannot be omitted.
*/
Let number = 0
Switch number
{
case 0:
Print("0")
let a = 998
Case 5:
Print("5")
case ten:
Print("ten")
default:
Print("Other")
}
Swift 2.0 Syntax Branch