I wish to create an interpreted Swift command-line utility. Thus, in Xcode 13.1, I create a new project, and use the template "Command Line Tool". This results in an empty project with a single file, called main.swift.
I want to distribute this command-line utility as a single file, so having the "main.swift" name isn't useful. I rename it to MyCommandlineProject.swift, then add the hashbang line on top, and add code that marks it as being the main file. The contents now look as follows:
#!/usr/bin/swift
import Foundation
@main
struct CLI {
static func main() {
print("Hello, World!")
}
}
Despite the @main annotation, I still get the following compiler error:
Hashbang line is allowed only in the main file
Why?