Swift Executable with @main

Hi,

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.

@main
struct Test {
    static func main() {
        print("hello")
    }
}

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

3 Likes
Terms of Service

Privacy Policy

Cookie Policy