Our first program demonstrates how to work with command-line arguments. Here’s the full source code:
NSProcessInfo provides access to command-line arguments. Note that the first value in this array is the path to the program, and [args subarrayWithRange:NSMakeRange(1, [args count] - 1)] holds the arguments to the program.
You can get individual args with normal indexing.
To experiment with command-line arguments, it’s best to compile the program first:
Next, we’ll look at more advanced command-line processing with options or flags.