Import Foundation//mark:-------Enumeration Syntax-----------//Not like C and objective-c. Swift's enumeration member will not be given a default integer value when it is created enum compasspoint{case, South case, West}enum planet{case Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, nepturn}var directiontohead = Compasspoint.westdirectiontohead =. E Astswitch directiontohead{case. North:print ("North") case. South:print ("South") case. East:print ("Orient") case. West:print ("West") Default:print ("Unknown Direction")}//mark:-------instance value (associated values)-----------//You can define the enumeration of Swift Stores no matter what type of instance value. Assuming the need. The data type of each member can be a different enum barcode{case UPCA (int, int., int) case QRCode (String)}var Productbarcode = BARCODE.UPCA (8, 85 909_51226, 3) Productbarcode =. QRCode ("Abcdefghijklmnop") switch productbarcode{case let. UPCA (Numbersystem, identifier, check): Print ("upc-a with value of \ (Numbersystem), \ (identifier), \ (check).") Case Let. QRCode (ProductCode): Print ("QR code with value of \" (ProductCode). ")} Output "QR code with value of Abcdefghijklmnop.//mark:-------Original value (raw values)-----------//Raw value can be a string. character, or whatever the integer value or floating-point value. Each primitive value must be unique within its enumeration declaration. When an integer value is used for the original value, assuming that the other enumeration members do not have values, they are actively incrementing themselves.Enum planetraw:int{Case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, neptune}//use the Toraw method of the enumeration member to access the original Starting value: Let Earthsorder = PlanetRaw.Earth.rawValueprint (earthsorder)//Earthsorder is 3//mark:----------- GCD demo----------var array = ["Jack", "Rose", "Jay", "Grace"];//declares a global concurrency queue, type dispatch_queue_t;dispatch_queue_priority _default for queue priority, default 0var queue:dispatch_queue_t = Dispatch_get_global_queue (dispatch_queue_priority_default, 0)// Opens a thread Dispatch_async (queue, {(), Void in print (Nsthread.currentthread (). Ismainthread? "This is the main thread": "This is the background thread")///The first parameter is the number of times. The third part of the block blocks the shape to distinguish the number of times.
Dispatch_apply (Array.count, queue, {(index:int), Void in print (String (index) + "---" + array[int (Index) ]})//callback main thread. Run UI Update Dispatch_async (Dispatch_get_main_queue (), {(), Void in print (Nsthread.currentthread (). Ismai Nthread? "This is the main thread": "This is the background thread")})
The enumeration syntax for swift tutorials