How do I access program arguments in Swift?

command-line, command-line-arguments, swift

Solution

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)

Problem

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?

Original source