7

I'm writing a command line app using Swift but I'm not sure how to get access to the arguments passed in. In C/Obj-c it seems relatively painless but if I try:

argv[0]

I get an error: Use of unresolved identifier 'argv'

Edward Loveall
  • 1,983
  • 1
  • 19
  • 34

1 Answers1

18

There are two ways to do this:

  1. The constants C_ARGC and C_ARGV. They are analogous to the argc and argv you'd see in a main() function.
  2. The CommandLine.arguments array will contain all of the arguments to the process. (In Swift 2, CommandLine was called Process)
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498