iOS two development (SWIFT) enumeration

Source: Internet
Author: User

//: Playground-noun:a Place where people can playImport UIKit//Raw Valueenummonth:string{ CaseJanuary ="value_january"     CaseFebruary ="value_february"     CaseMarch ="Value_march"     CaseApril ="Value_april"     CaseMay ="Value_may"     CaseJune ="Value_june"     CaseJuly ="value_july"     CaseAugust ="Value_august"     CaseSeptember ="Value_september"     CaseOctober ="Value_october"     CaseNovember ="Value_november"     CaseDecember ="Value_december"}func season (Month:month)-string{SwitchMonth { Case . January:returnMonth.rawvaluedefault:        return ""}}season (month:Month.January) print (Month.april)ifLet July = Month (rawValue:"value_july") {print (July)}//Associate Value//Example 1enumatmstatus{ CaseSuccess (Int) CaseError (String) CaseWaiting}var Balance= +func Withdraw (amount:int)-atmstatus{ifAmount <=Balance {Balance-=Amountreturn . Success (Balance)}Else {        return. Error ("Not enough money")}}let result= Withdraw (Amount: -)SwitchResult { CaseLet . Success (newbalance): Print ("\ (newbalance) Yuan left on your account.")     CaseLet . Error (errormessage): Print ("error:\ (errormessage)")     Case . Waiting:print ("Waiting")}SwitchResult { Case . Success:print ("Success")     Case . Error:print ("Error")     Case . Waiting:print ("Waiting")}//Example 2enumshape{ CaseSquare (side:double) CaseRectangle (width:double, height:double) CaseCircle (centerx:double, centery:double, radius:double) CasePoint}let Square= Shape.square (side:Ten) Let Rectangle= Shape.rectangle (width: -, Height: -) Let Circle= Shape.circle (CenterX:0, CenterY:0, Radius: the) Let point=Shape.pointfunc Area (shape:shape)-double{SwitchShape { CaseLet . Square (side):returnSide *side CaseLet . Rectangle (width, height):returnWidth *Height CaseLet . Circle (_, _, R):returnM_PI * R *R Case . Point:return 0}}area (shape:square) area (shape:rectangle) area (shape:circle) area (shape:point)

iOS two development (SWIFT) enumeration

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.