In the previous step, while playing with xcrun
, we discovered that there are two different swift compiler tools: swift
and swiftc
. If you get help for with the -h
command, you will notice that they are both Swift compilers with similar options, but there is a difference.
The swift
tool compiles and executes swift code. If you run it without any arguments, it will launch a REPL and give you the ability to evaluate the Swift code.
You can also pass a Swift file that you want to run as a parameter. We can simply create a swift file from the command line:
echo 'print("Hello World")' > main.swift xcrun swift main.swift Hello World
You can also pass additional options, such as -O
to enable optimization:
xcrun swift -O main.swift