Skip to main content

Basics for Swift and SwiftUIs

Swift basics are the foundations of the language: constants and variables, type inference, optionals, collections, control flow with if, switch and loops, and functions with labelled parameters. Closures, which are self-contained blocks of code that capture values, appear throughout Swift and SwiftUI APIs, so they belong to this first stage.

Stage: Swift Language · Part of the Swift and SwiftUI roadmap · Last reviewed 19 November 2026

What to learn in Basics

Basics interview questions

What is an optional in Swift and why does it exist?

An optional is a type that either holds a value or is nil, written like Int?. It makes the possible absence of a value explicit, so the compiler forces you to handle it and avoids many null-reference crashes common in other languages.

What is the difference between guard let and if let?

Both unwrap an optional. if let makes the unwrapped value available only inside its block, while guard let makes it available for the rest of the scope and requires an early exit, such as return, when the value is nil.

Where Basics fits in the Swift and SwiftUI roadmap

Basics belongs to the Swift Language stage (beginner level), which takes about 28 hours. Types and safety.

Back to the full Swift and SwiftUI roadmap