Swift Study Notes 01

Source: Internet
Author: User

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

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.