Suppose requirement is to enumerate list of languages.
Add this to .h file
typedef NS_ENUM(NSInteger, AvailableLanguage) {
ENGLISH,
GERMAN,
CHINENSE
};
Now, in .m file simply create an array like,
// Try to use the same naming convention throughout.
// That is, adding ToString after NS_ENUM name;
NSString* const AvailableLanguageToString[] = {
[ENGLISH] = @"English",
[GERMAN] = @"German",
[CHINESE] = @"Chinese"
};
Thats it. Now you can use enum with easy and get string for enums using array. For example,
- (void) setPreferredLanguage:(AvailableLanguage)language {
// this will get the NSString* for the language.
self.preferredLanguage = AvailableLanguageToString[language];
}
Thus, this pattern depends on accepted naming convention of NS_ENUM and companion ToString array. Try to follow this convention through out and it will become natural.