Using the Swift compiler
The Swift compiler is the basic utility to build Swift code and it is used by the package manager, Xcode, and any other utility that builds Swift code into executables. We can also call it ourselves. To see how to call it ourselves, create a file named hello.swift
and add the print("Hello, world!")
code to it as shown with the following code:
echo `print("Hello, world!")` >> hello.swift
Now we can compile this code with the following command, which calls the Swift compiler:
swiftc hello.swift
Finally we can execute the newly created application like we would any other executable:
./hello
And we will be greeted with our Hello, world!
message.