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