Accessing / passing command line arguments

I see there is an option in Fire under Project > Manage Start-Up Arguments to set arguments. Presumably these are arguments that will be passed to the application on start up when debugging, much like a command line argument when run from a Terminal?

When using the default Swift macOS console application template, Fire generates a single program.swift file that just contains:

import Foundation
print("The magic happens here")

How would I access arguments passed to the application without a containing main() function?

Swift exposes two standard globals for that, C_ARGC is the count and C_ARGV is an [String]. I know, beautifully designed API… ;O

Alternatively, (in all languages) you can of course explicitly declare as main() function, such as

public func main(_ args: String[]) {

rather than the flat entry point. And global (or static) func named ”main” with the correct signature will be accepted as entry point; provided there’s one and only one.

(i believe the argument has to be of type String[], which is a platform-native array type, rather than [String] (which is a struct implemented in the Swift Base Library and thus not compatible with what the OS level entry point expects); but i could be wrong, maybe either works.

We’ll also me supporting the new @main things that’s currently being discussed, once that’s settled.

1 Like

Thank you Marc. I have to say, the customer support for this product is absolutely fantastic.


happy to hear; glad to be of service!

1 Like