Swift Executable with @main


I was trying to use @main using a swift executable swift package init --type executable. The code below builds and runs in Xcode but when I try to run the code in terminal I get the error " 'main' attribute cannot be used in a module that contains top-level code". I was wondering why that might be and if this might be a bug? I am still fairly new with Swift, thanks for your help in advance.

struct Test {
    static func main() {

This is a known bug. https://bugs.swift.org/browse/SR-12683

Terms of Service

Privacy Policy

Cookie Policy