Created
April 29, 2015 21:30
-
-
Save rsattar/d0337a742f5bcd569f3c to your computer and use it in GitHub Desktop.
Template for creating string <-> enum conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In .h | |
typedef NS_ENUM(NSInteger, ClusterAPIClusterMediaKind) { | |
ClusterAPIClusterMediaKindPhoto = 1 << 1, | |
ClusterAPIClusterMediaKindVideo = 1 << 2, | |
ClusterAPIClusterMediaKindText = 1 << 3, | |
ClusterAPIClusterMediaKindFancyText = 1 << 4, | |
ClusterAPIClusterMediaKindLocation = 1 << 5, | |
}; | |
+ (ClusterAPIClusterMediaKind) mediaKindFromString:(NSString *)kindString; | |
+ (NSString *) stringFromMediaKind:(ClusterAPIClusterMediaKind)kind; | |
// In .m | |
+ (ClusterAPIClusterMediaKind) mediaKindFromString:(NSString *)kindString | |
{ | |
if (![kindString isKindOfClass:[NSString class]]) { | |
return ClusterAPIClusterMediaKindPhoto; | |
} | |
if ([kindString isEqualToString:@"v"]) { | |
return ClusterAPIClusterMediaKindVideo; | |
} else if ([kindString isEqualToString:@"t"]) { | |
return ClusterAPIClusterMediaKindFancyText; | |
} else if ([kindString isEqualToString:@"x"]) { | |
return ClusterAPIClusterMediaKindText; | |
} else if ([kindString isEqualToString:@"l"]) { | |
return ClusterAPIClusterMediaKindLocation; | |
} else { | |
return ClusterAPIClusterMediaKindPhoto; | |
} | |
} | |
+ (NSString *) stringFromMediaKind:(ClusterAPIClusterMediaKind)kind | |
{ | |
switch (kind) { | |
case ClusterAPIClusterMediaKindFancyText: | |
return @"t"; | |
break; | |
case ClusterAPIClusterMediaKindText: | |
return @"x"; | |
break; | |
case ClusterAPIClusterMediaKindVideo: | |
return @"v"; | |
break; | |
case ClusterAPIClusterMediaKindLocation: | |
return @"l"; | |
break; | |
case ClusterAPIClusterMediaKindPhoto: | |
default: | |
return @"p"; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment