Skip to content

Instantly share code, notes, and snippets.

@uroboro
Last active November 20, 2022 02:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uroboro/8782641c7d2412427b5487254e8f40b0 to your computer and use it in GitHub Desktop.
Save uroboro/8782641c7d2412427b5487254e8f40b0 to your computer and use it in GitHub Desktop.
Objective-C switch statement with strings.
#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