In Objective-C there is no built in enums available for String types. You can declare enums as Integer and then make a function or an array of strings which return the string value for that enum.
Declare in your .h file.
typedef NS_ENUM(NSInteger, FRUIT) {
APPLE = 1,
GRAPE,
ORANGE,
PINEAPPLE,
LEMON,
All
};
extern NSString * const FRUITString[];
Define in your .m file.
NSString * const FRUITString[] = {
[APPLE] = @"APPLE",
[GRAPE] = @"GRAPE",
[ORANGE] = @"ORANGE",
[PINEAPPLE] = @"PINEAPPLE",
[LEMON] = @"LEMON",
[All] = @"All"
};
and you can use it like:
NSLog(@"%@", FRUITString[APPLE]);
// OR
NSLog(@"%@", FRUITString[1]);
Output: APPLE
Based on your comment: if food values is "food":"1,2" I want to show "apple,grape"
NSString *foodValue = @"1,2";
NSArray *values = [foodValue componentsSeparatedByString:@","];
NSMutableArray *stringValues = [[NSMutableArray alloc] init];
for (NSString *value in values) {
[stringValues addObject:FRUITString[[value integerValue]]];
}
NSLog(@"%@", [stringValues componentsJoinedByString:@","]);
APPLE,GRAPE