Write your code in a file named hello.swift:

print("Hello, world!")

To launch a terminal, press CTRL+ALT+T on Linux, or find it in Launchpad on macOS. To change directory, enter cddirectory_name (or cd .. to go back)

swift hello.swift

A compiler is a computer program (or a set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language), with the latter often having a binary form known as object code. (Wikipedia)

swiftc hello.swift

This will compile your code into hello file. To run it, enter ./, followed by a filename.

./hello

Code:

func greet(name: String, surname: String) {
    print("Greetings \\(name) \\(surname)")
}

let myName = "Homer"
let mySurname = "Simpson"

greet(name: myName, surname: mySurname)

Let’s break this large code into pieces:

Running it using REPL:

swiftfunc greet(name: String, surname: String) {print("Greetings \\(name) \\(surname)")}let myName = "Homer"let mySurname = "Simpson"greet(name: myName, surname: mySurname)