001-Enumeration
//enumeration is not assigned to the default integer value in Swiftenumsomeenumeration { Case North CaseSourth CaseEast CaseWest}//multiple member values to be written in one line, separated by commasenumPlanet { CaseMercury,earth,mars}var Directionhead=someenumeration.west Directionhead=. East//using switch to match a single enumeration value SwitchDirectionhead { Case. North:print (" North") Case. Sourth:print ("Sourth") Case. West:print ("West") Case. East:print ("East") default: Print ("None of this Direction") }
Enumerate associated values
enum BarCode { case UPC (int,int,int,int) // According to the digital identification commodity case qrcode (String) //
}
//
Create a barcode var productbar = BARCODE.UPC (
8 ,
8 ,
3 ,
4
) Productbar =. QRCode (
"
abcde
" )
//
UPC replaced by QRCode
Enumerate original values
//the original value of the enumeration hermit assignmentenumAsciicontrolchar:character { Casetab ="\ t" Caselinefeed ="\ n" CaseCarriagereturn ="\ r"}//the default value of the string is the enumeration value itselfenumplanet:int{ CaseMercury =1, Venus,earth,mars}//gets the original value of the enumeration variableLet Earthorder =Planet.earth.rawValue Print (earthorder)//output is 3
Enumerate recursion
//Enumerate recursionIndirectenumArithmetic { CaseNumber (Int) Caseaddition (arithmetic,arithmetic) Casemultiplication (arithmetic,arithmetic)}//Create an enumeration recursive expressionLet five = Arithmetic.number (5) let four= Arithmetic.number (4) Let sum=Arithmetic.addition (five, four) let product=arithmetic.multiplication (sum, five)//(5+4) * 5Print (product)
Class
// declaration of the class: class student{ "" // access Properties " Kid " print (classitem.name)// Kid
//Structure :
// Structural Body struct Teacher { "" = teacher () print (myteacher)/ /Teacher (name: "", age:20)
Swift-class, struct, enum