Swift Basic usage-switch usage

Source: Internet
Author: User

Playground-noun:a place where people can playimport uikit//------------------------------------------------------- -----------------------//1. Basic use//switch and OC difference://1> do not need to write break//2> each branch of the conditions of the instructions can not write//3> case If you take multiple values, you may use "," separated var grand = "a" var Result:strin        Gswitch grand.uppercasestring {case "A": result = "excellent \ (grand)" Case "B": result = "good" case "C": result = "Medium" case "D", "E", "F": result = "difference" Default:result = "Unknown"}//--------------------------------- ---------------------------------------------//2.  Variable/Chang value//In case matching, you can bind the value in switch to a specific constant or variable to use var point = (Ten) in the case's statement (let X, 0): Result = "This point is on the x axis, the x value is \ (x)" case (0, let y): result = "This point is on the Y axis, the Y value is \ (y)" Case let (x, y): result = "The x value of this point is \ (x), Y value is \ (y)"} ------------------------------------------------------------------------------//3. where//use where can increase the judging condition var point1 = ( -10) switch Point1 {case let (x, y) where x = = Y:result = "On the \ \ Diagonal "Case let (x, y) where x = =-y:result =" On/diagonal "Default:result =" not on diagonal "}//------------------------- -----------------------------------------------------//4. fallthrough//after executing the current case, continue executing the following case or the default statement var num = 20var str = "\ (num) is" switch num {case 0...50:STR + = "0~50 The "Fallthroughdefault:str + =" Integer "}

Swift Basic usage-switch usage

Related Article

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.