Hi there,
main is common used naming for executables that contains main function. It’s
required by Swift compiler and Swift Package Manager can’t do anything about
that.
If you create a simple command line tool in Xcode, it will create main.swift
file. If you try to rename it, it will feil.
I think this is correct behaviour.
If you still think that Swift should support Main.swift with upper case letter,
than it should be discussed with compiler team.
- Kostiantyn
> Hi there,
>
> This is what happened as I was trying out the Swift Package Manager for
> another project similar to the one shown below:
>
> ~ $ mkdir example
> ~ $ cd example/
> example $ touch Package.swift
> example $ mkdir Sources
>
> example $ vi Sources/Example.swift
> example $ cat Sources/Example.swift
> func printOther() {
> print("other")
> }
>
> example $ vi Sources/Main.swift
> example $ cat Sources/Main.swift
> print("Hello World")
> printOther()
>
>
> example $ swift build
> Compile Swift Module 'example' (2 sources)
> /PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at
> the top level
> print("Hello World")
> ^
> /PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at
> the top level
> printOther()
> ^
> /PATH/example/Sources/Main.swift:1:1: error: expressions are not allowed at
> the top level
> print("Hello World")
> ^
> /PATH/example/Sources/Main.swift:2:1: error: expressions are not allowed at
> the top level
> printOther()
> ^
> <unknown>:0: error: build had 1 command failures
> error: exit(1): /PATH-SWIFT/usr/bin/swift-build-tool -f
> /PATH/example/.build/debug.yaml
>
>
> example $ mv Sources/Main.swift Sources/main.swift
> example $ swift build
> Compile Swift Module 'example' (2 sources)
> Linking .build/debug/example
> example $ .build/debug/example
> Hello World
> other
> example $
>
>
> I had to renameMain.swifttomain.swift. Is there a design decision on why the
> filename for the main swift file has to be lowercase or is this a bug?
>
> If it’s a design decision, why are directory names forsource files allowed to
> have variations likeSources,Source,srcandsrcsas
> statedhere(https://github.com/apple/swift-package-manager/blob/master/Documentation/SourceLayouts.md#other-rules)but
> not the main swift file?
>
> I’d be ok if onlyMain.swiftandmain.swiftare allowed since other files in
> theSourcesdirectory are commonly UpperCamelCasedue to the Type naming
> conventions
> e.g.example-package-playingcard/Sources(https://github.com/apple/example-package-playingcard/tree/master/Sources).
>
> Or maybe I’m just being pedantic?
>
> p.s. evenPackage.swiftis capitalized and notpackage.swift
>
> $ swift --version
> Swift version 3.0-dev (LLVM 752e1430fc, Clang 1e6cba3ce3, Swift 56052cfe61)
> Target: x86_64-unknown-linux-gnu
>
>
>
>
> _______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users