How to use @main annotation: I figure out how by deleting `main.swift`, did I do it right?

In Xcode, I created a macOS Command Line Tool project which include a main.swift file. I want to use @​main annotation on ParsableCommand. When @​main is added to a ParsableCommand, I get error:

'main' attribute cannot be used in a module that contains top-level code

When I delete the main.swift file, it fixed the problem and work. Is this the correct thing to do?

Is there some documentation explaining how to use @​main for ArgumentParser app?

Yes, it's an either @main or main.swift type of choice.

I guess you just annotate the desired conforming type with @main and that's it. The package already provides the required main() static method to kick everything off.

1 Like

Correct! I've opened an issue to track adding documentation for this.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy