Enumeration used in OC development and enumeration in oc
Definition of a common enumeration:
typedef enum{LOGIN_SUCCESS,USER_NAME,USER_PASSWORD,OLD_LAT,OLD_LNG}FIELD_SAVED;
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.