Swift 2.0 Syntax Branch

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.