Enumeration used in OC development and enumeration in oc

Source: Internet
Author: User

Enumeration used in OC development and enumeration in oc


Definition of a common enumeration:



2. After iOS6 and Mac OS 10.8, Apple introduced two macros to redefine the two enumeration types. In fact, the enum definition and typedef are combined into one, different macros are used to distinguish them from the code perspective.

Typedef NS_ENUM (NSInteger, UIViewAnimationTransition) {UIViewAnimationTransitionNone, // The default value is starting from 0, starting from success, failed, failed,}; typedef NS_OPTIONS (NSUInteger, UIViewAutoresizing, latency = 1 <0, UIViewAutoresizingFlexibleWidth = 1 <1, latency = 1 <2, latency = 1 <3, UIViewAutoresizingFlexibleHeight = 1 <4, UIViewAutoresizingFlexibleBottomMargin = 1 <5 };


Three enumerations are often used to replace characters. For example, you can convert an enumerative type to a character.

Convert enumeration to character.

-(NSString*) getStringFromField:(FIELD_SAVED)defaultFiled{    switch (defaultFiled) {        case LOGIN_SUCCESS:            return @"login_success";        case USER_NAME:            return @"user_name";        case USER_PASSWORD:            return @"user_pwd";        case OLD_LAT:            return @"lat";        case OLD_LNG:            return @"lng";        default:            return @"default";    }}

Find the corresponding String Based on the requested data:

1 first define an array of all enumerated values.

2. Return the subscript Based on the requested data.

3. obtain the corresponding String Based on the subscript.




Enumeration is usually used in actual java development.

Generally, you won't use it in the lower part.

The enumerated content used by the company is generally encapsulated.

Generally, in actual projects, you cannot use enumeration ,'

Even if there are, there are very few.

Which is the ratio of c to oc used in iOS development?

The oc is a set of c supersets, which are closely related to each other. Generally, 100% of projects must be oc. They are all advanced extensions Based on c, and occasionally use some features of c, such as variable definitions of basic data types and some simple mathematical methods. C has been learned, which is of great help to oc.

Related Article

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.