Last active
April 11, 2021 09:11
-
-
Save Kam-To/a8a16dd026a06a9683d7ded180730f4a to your computer and use it in GitHub Desktop.
handy marco for key-value binds support nil value in value list
This file contains 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
#define KTOptionalBindings(...) __KTOptionalBindings(@#__VA_ARGS__,__VA_ARGS__) | |
NSMutableDictionary *__KTOptionalBindings(NSString *command_value_list, id firstValue, ...) { | |
va_list args; | |
va_start(args, firstValue); | |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; | |
NSArray *keys = [command_value_list componentsSeparatedByString:@", "]; | |
NSInteger inputCount = keys.count; | |
for (NSInteger i = 0; i < inputCount; i++) { | |
NSString *key = keys[i]; | |
id val = nil; | |
if (i == 0) { | |
val = firstValue; | |
} else { | |
val = va_arg(args, id); | |
} | |
dict[key] = val; | |
} | |
va_end(args); | |
return dict; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment