Last active
November 20, 2022 02:27
-
-
Save uroboro/8782641c7d2412427b5487254e8f40b0 to your computer and use it in GitHub Desktop.
Objective-C switch statement with strings.
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
#include <stdio.h> | |
#import <Foundation/Foundation.h> | |
int main(int argc, char **argv) { | |
NSArray * options = @[ | |
@"-h", | |
@"--help", | |
@"--get", | |
@"--set", | |
]; | |
for (int i = 0; i < argc; i++) { | |
switch ([options indexOfObject:@(argv[i])]) { | |
case 0: | |
case 1: | |
printf("This is the help message"); | |
break; | |
case 2: | |
printf("Get something"); | |
break; | |
case 3: | |
printf("Set something"); | |
break; | |
default: | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment