Enum and typedef

Source: Internet
Author: User
Tags aliases

Enum type creates an enumeration using the Emum keyword.
    1. // defines an enumeration that represents a direction Enumdirection{up,down,middle,left,right};

The value of the enumeration can be represented by a number, and is incremented by default from zero
Enumdirection Direction =Up ;//Output 0NSLog (@"Direction =%i", direction);d irection=Down ;//Output 1NSLog (@"Direction =%i", direction);d irection=Middle;//Output 2NSLog (@"Direction =%i", direction);d irection=Left ;//Output 3NSLog (@"Direction =%i", direction);d irection=Right ;//Output 4NSLog (@"Direction =%i", direction);

    1. The value of the custom enumeration.

The value of the enumeration is incremented by default from zero, the next enumeration value is the previous enumeration value +1, and if we customize the enumeration value, then the next enumeration value is the previous custom enumeration value +1

    1. enumdirection{up,//  0down=,//Middle,//11 left,//+ right//;

Convert numbers to enumerations

Because enumerations are represented by numbers, numbers can also be converted to enumerations.

    1. // Defining Enumerations Enumdir{up,down}; // number to enumerate enumdir dir =0; // detect if they are equal if (dir = = up ) {NSLog (@ " equals ... " );}

typedef definition Aliases typedef can define aliases for complex declarations, such as the enumerations above us.
    1. // enable alias typedefenumdirdirection for enum Dir ;

With the alias definition as above, we can use the Dir enumeration in the subsequent use
    1. // enumeration using aliases Direction Direction = up;

typedef can define not only enum aliases, int, float and other types can be defined

The Nsinteger we will use later is the alias definition of Int. The "icon in the Xcode code Editor represents a typedef alias.



From for notes (Wiz)



Enum and typedef

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.