Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I access argv and argc in swift? [duplicate]

Tags:

swift

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'

like image 892
Edward Loveall Avatar asked Jun 08 '14 20:06

Edward Loveall


1 Answers

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)
like image 142
Dave DeLong Avatar answered Nov 15 '22 08:11

Dave DeLong