To have the enumeration value correspond to string one by one

Source: Internet
Author: User

To have the enumeration value correspond to string one by one

Description

The uniform Management of strings, which can be represented by numeric values, is intended to increase the readability of the code.

Source

Https://github.com/YouXianMing/StringAndValue

////StringAndValue.h//Stringandvalue////Created by youxianming on 15/6/9.//Copyright (c) 2015 youxianming. All rights reserved.//#import<Foundation/Foundation.h>#defineE_string (value) [Stringandvalue stringvaluewithestringandvalue: (value)]#defineE_value (value) [Stringandvalue numbervaluewithestringandvalue: (value)]typedefenum: Nsuinteger {eusersucess, Eusererror,} estringandvalue;@interfaceStringandvalue:nsobject/** * Get value * * @param Value enumeration value * * @return value*/+(Estringandvalue) Numbervaluewithestringandvalue: (estringandvalue) value;/** * gets the string corresponding to the value * * @param Value enumeration value * * @return string*/+ (NSString *) Stringvaluewithestringandvalue: (estringandvalue) value;@end
////STRINGANDVALUE.M//Stringandvalue////Created by youxianming on 15/6/9.//Copyright (c) 2015 youxianming. All rights reserved.//#import "StringAndValue.h"StaticNsdictionary *_datastringandvalue =Nil;@implementationStringandvalue+ (void) Initialize {if(self = = [Stringandvalueclass]) {_datastringandvalue= @{@ (eusersucess):@"Success", @ (eusererror):@"failed",}; }}+(Estringandvalue) Numbervaluewithestringandvalue: (estringandvalue) value {returnvalue;}+ (NSString *) Stringvaluewithestringandvalue: (estringandvalue) value {return_datastringandvalue[@ (value)];}@end
////VIEWCONTROLLER.M//Stringandvalue////Created by youxianming on 15/6/9.//Copyright (c) 2015 youxianming. All rights reserved.//#import "ViewController.h"#import "StringAndValue.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; NSLog (@"%@", E_string (Eusererror)); NSLog (@"%lu", (unsignedLong) eusererror);}@end

The important place

To have the enumeration value correspond to string one by one

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.