Skip to content

Instantly share code, notes, and snippets.

@gavrix
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavrix/8961770 to your computer and use it in GitHub Desktop.
Save gavrix/8961770 to your computer and use it in GitHub Desktop.
objc NSDictionary literals vs c-style switch
NSInteger sourceIntValue;
id mappedValue = (@{@(kSomeConstValue1): KSomeConstMappedValue1,
@(kSomeConstValue2): KSomeConstMappedValue2}[@(sourceIntValue)])?:KSomeConstMappedDefaultValue;
//VS
id mappedValue;
switch(sourceIntValue) {
case kSomeConstValue1:
mappedValue = KSomeConstMappedValue1;
break;
case kSomeConstValue2:
mappedValue = KSomeConstMappedValue2;
break;
default:
mappedValue = KSomeConstMappedDefaultValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment