Edward Loveall Edward Loveall - 1 year ago 151
Swift Question

How to I access argv and argc in 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:


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

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download