Swift Get Started
Getting started with Swift is writing a program file, compiling it, and running the compiled program.
A one statement file
You write this file first, then compile it, then run it. Its single statement prints one line.
print("Ready")Statements in order
Step one appears above Step two in the output. The order on screen matches the order in the file.
print("Step one")
print("Step two")A short first run
This file holds two statements. Each statement prints its own line.
print("My program")
print("It works")Example
print("Program starts")
print("Program ends")Key points
- The program file in this course is main.swift.
- Use swiftc main.swift to compile the file into a program.
- A statement is one complete instruction in a program.
- Statements run from top to bottom.
In this example, the first statement prints Program starts. The second statement prints Program ends below the first line.
Try it Yourself
Edit the code, then press Run.
Running is simulated ยท Programiz Swift Compiler
Exercise
Which command compiles the file main.swift?