Swift Basic Syntax (v) enumeration, the difference between struct and class

Source: Internet
Author: User

The struct values in Swift can be integer, floating point, String, character, Ganso, if the value is not assigned by default to integer and starts at 0, if an integer enumeration and requires that the value of the first value of the enumeration is not starting from 0, the values are automatically followed by 1

References also differ from OC

// Enumeration Definitions enum enumeration Name {    case  identifier 1, identifier 2    case  identifier 3 (Type list)    case Identifier 4= Value}// reference enumeration name. identifier // or direct . identifier

Enumerating multiple types of reads

enumBarcode { CaseUPCA (int, int, int) CaseQRCode (String)}//Assign Valuevar a = BARCODE.UPCA (111,222,333) A=. QRCode ("Hello")//Note the same variable can only use the. Identifier () to manipulate the value of the second enumeration structure when it wants to assign it//ReadSwitchProductbarcode { Case . UPCA (Let-numbersystem, let-identifier, let check): println ("upc-a with value of \ (Numbersystem), \ (identifier), \ (check).") Case . QRCode (Let ProductCode): println ("QR code with value of \ (ProductCode).")}

The difference between a class and a struct:

1. struct supports static and static variables

2. The struct does not support delegation

Swift Basic Syntax (v) enumeration, the difference between struct and class

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.