Ios-swift-enumeration and struct body

Source: Internet
Author: User

1. Enumeration

Create an enumeration using the keyword enum.

The default starting value of the enumeration is 0, and you can customize the starting value.

A method can be defined in an enumeration, as defined in a class.

Accesses the value of the current enumeration using the keyword RawValue.

    enumRank:int { CaseAce =1         CaseThree, four, five, six, seven, eight, nine, ten CaseJack, Queen, King Func simpledescription ()-String {SwitchSelf { Case. Ace:return "Ace"             Case. Jack:return "Jack"             Case. Queen:return "Queen"             Case. King:return "King"            default:                returnString (Self.rawvalue)}} } Let Ace=Rank.ace let Acerawvalue= Ace.rawvalue

And also

    if 3 ) {        = convertedrank.simpledescription ()    }

And also

    enumSuit { CaseSpades, Hearts, diamonds, clubs func simpledescription ()-String {SwitchSelf { Case. Spades:return "Spades"             Case. Hearts:return "Hearts"             Case. Diamonds:return "Diamonds"             Case. Clubs:return "Clubs"}}} let hearts=suit.hearts let Heartsdescription= Hearts.simpledescription ()
2 Structural bodies

Use the keyword struct to create the struct body.

Structs and classes are similar, including methods and initialization. The biggest difference between a struct and a class is that the struct is a copy of the value during the pass, and the class is a reference copy.

    struct Card {        var rank:rank        var suit:suit        - String {            return'  The \ (Rank.simpledescription ()) of \ (Suit.simpledescription ())"        }    }    = Card (rank:. Three, suit:. Spades)     = Threeofspades.simpledescription ()

Well, try.

Ios-swift-enumeration and struct body

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.