Random programming things I'd want to remember

Saturday, March 3, 2012

XCode 4.2: how to provide arguments to a command-line app

Here is how to provide arguments to a program in XCode 4.2:
Product -> Edit Scheme

Click on "Run" in the left-side part of the dialog box. If needed, switch to "Arguments" tab in the middle part of the dialog box. Under "Arguments Passed On Launch", press "+" and add a value. Then you can access the value using the following code:
NSProcessInfo *proc = [NSProcessInfo processInfo];
NSArray *args = [proc arguments];
NSString *myArg = [args objectAtPosition: 1];

One note worth mentioning: if your argument contains spaces, enclose it in quotes: "my argument".

No comments: