SwSwift · Lesson 1 of 8

Hello, Swift

Clean syntax, strong types, no semicolons. Swift reads like pseudocode but compiles to machine code as fast as C++ in many benchmarks.

Swift
// hello.swift — run with: swift hello.swift
print("Hello, World!")

let name = "Ada"        // let = constant (use by default)
var age = 17            // var = mutable
age = 18
// name = "Bob"         // error: 'name' is a let constant

print("I'm \(name), age \(age)")     // string interpolation
print("Next year: \(age + 1)")

Types are inferred but static: let name = "Ada" is a String forever. Explicit annotations use a colon — let name: String = "Ada". As in Kotlin and Rust, prefer immutable (let) and reach for var only when mutation is the point.

Swift
let int: Int = 42
let double: Double = 3.14
let bool: Bool = true
let text: String = "hello"

// No implicit conversions — be explicit:
let sum = Double(int) + double

// Multi-line strings:
let poem = """
    Roses are red,
    Swift compiles too.
    """

// Type check and conversion:
type(of: int)               // Int
let parsed = Int("123")     // Int? — might fail! (next lesson)
◆ Note
Int("123") returns Int? — an optional — because the string might not be a number. Swift makes every 'this could fail' visible in the type. That question mark is the heart of the language, and the next lesson.