How do I access program arguments in Swift?

zneak picture zneak · Jun 3, 2014 · Viewed 16.1k times · Source

C and derivatives have argc and argv (and envp) parameters to their entry point functions, but Swift doesn't have one proper: top-level code is just code and it doesn't have parameters.

How can one access the equivalent of argc and argv in a Swift program?

Answer

ambientlight picture ambientlight · Aug 16, 2016

Process was just renamed into CommandLine (since Swift 3.0 August 4 snapshot)

let arguments = CommandLine.arguments

(for some reason this wasn't mentioned on the changelog)