<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/CommandLine/arguments",
  "metadataVersion" : "0.1.0",
  "role" : "Type Property",
  "symbol" : {
    "kind" : "Type Property",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s11CommandLineO9argumentsSaySSGvpZ"
  },
  "title" : "arguments"
}
-->

# arguments

An array that provides access to this program’s command line arguments.

```
static var arguments: [String] { get set }
```

## Discussion

Use `CommandLine.arguments` to access the command line arguments used
when executing the current program. The name of the executed program is
the first argument.

The following example shows a command line executable that squares the
integer given as an argument.

```
if CommandLine.arguments.count == 2,
   let number = Int(CommandLine.arguments[1]) {
    print("\(number) x \(number) is \(number * number)")
} else {
    print(
      """
      Error: Please provide a number to square.
      Usage: command <number>
      """
    )
}
```

Running the program results in the following output:

```
$ command 5
5 x 5 is 25
$ command ZZZ
Error: Please provide a number to square.
Usage: command <number>
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)