How to access argv and argc in swift?

I am writing a command line application using Swift, but I'm not sure how to access the arguments passed. In C / Obj-c, this seems relatively painless, but if I try:

argv[0]

I get an error: Using unresolved id 'argv'

+4
source share
1 answer

There are two ways to do this:

  • Constants C_ARGCand C_ARGV. They are similar to argcand argvthat you see in the function main().
  • The array CommandLine.argumentswill contain all the process arguments. (In Swift 2, CommandLinewas called Process)
+14
source

Source: https://habr.com/ru/post/1543788/


All Articles