Swift Tutorial
Learn Swift and start building iOS and macOS applications. This mini-course covers the fundamentals you need to get started with Apple's modern programming language.
Learn Swift from scratch — variables, optionals, collections, structs, classes, protocols, generics, closures, error handling, ARC, async/await and Codable —…
Part of the free Swift course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
New to Swift? No experience needed.
Start with Lesson 1 — Introduction to Swift. We'll guide you through everything from scratch, step by step.
Lessons in this course
- Introduction to Swift — What Swift is, why Apple created it, and how to write your first line of code
- Variables and Data Types — Strings, integers, doubles, booleans — and Swift's type inference system
- Control Flow — if/else, switch statements, and guard clauses for safer code
- Functions and Closures — Define reusable functions and understand Swift's powerful closure syntax
- Object-Oriented Programming — Classes, structs, inheritance, and protocols in Swift
- SwiftUI Basics — Build your first iOS screen using Apple's declarative UI framework
- Working with APIs — Fetch data from the internet with URLSession and decode JSON responses
- Optionals & nil Safety — Swift's signature feature — handle missing values safely with ?, if let and ??
- Strings & String Interpolation — Build and manipulate text with interpolation, multiline strings and methods
- Arrays — Store ordered lists — append, index, iterate, and the [T] type
- Dictionaries & Sets — Key-value lookups with dictionaries and unique collections with sets
- Tuples — Group values together and return multiple results from a function
- Enumerations & Associated Values — Model a fixed set of cases — raw values, associated values, and switch
- Structs & Value Types — Value semantics, memberwise initializers, and mutating methods
- Classes & Reference Types — Reference semantics, init/deinit, inheritance — and struct vs class
- Properties: Stored, Computed & Observers — Stored vs computed properties, willSet/didSet, lazy and static
- Methods & Initializers — Instance and type methods, designated vs convenience initializers, self
- Closures in Depth — Trailing closures, capturing values, escaping vs non-escaping, shorthand
- map, filter & reduce — Transform collections functionally with map, filter, reduce and compactMap
- Protocols — Define requirements as contracts and program to interfaces
- Extensions — Add functionality to existing types — even ones you don't own
- Generics — Write flexible, reusable code over many types with type constraints
- Protocol-Oriented Programming — Swift's signature paradigm — default behavior via protocol extensions
- Error Handling (do/try/catch) — Throw and catch errors with the Error protocol, try?, and try!
- guard & defer — Exit early with guard and schedule cleanup with defer
- Optional Chaining — Safely call into a chain of optionals with a?.b?.c
- Type Casting (is, as?) — Check and convert types with is, as?, as! and Any/AnyObject
- Access Control — Control visibility with open, public, internal, fileprivate and private
- Memory Management & ARC — How ARC works, retain cycles, and weak/unowned references
- Concurrency: async/await — Modern asynchronous Swift with async/await, Task and actors
- Codable & JSON — Encode and decode JSON effortlessly with Codable and CodingKeys
- The Result Type — Model success and failure explicitly with Result<Success, Failure>
- SwiftUI Views & the body Property — The View protocol, the body property, and composing Text, Image and Button
- @State & @Binding — Local source-of-truth state and two-way bindings in SwiftUI
- @StateObject & ObservableObject — Reference-type view models with @Published, @StateObject vs @ObservedObject
- @EnvironmentObject & the Environment — Inject shared data deep into the view tree and read @Environment values
- Layout: Stacks, Frames & GeometryReader — VStack/HStack/ZStack, alignment, frames and GeometryReader
- Lists, ForEach & Navigation — List, ForEach with Identifiable, and NavigationStack/NavigationLink
- Forms & User Input — Form, TextField, Toggle, Picker and Stepper bound to state
- Animations & Transitions — Implicit vs explicit animation, withAnimation and view transitions
- Custom View Modifiers & ViewBuilder — The ViewModifier protocol, custom modifiers and @ViewBuilder
- Introduction to Combine — Publishers, subscribers, @Published, sink and AnyCancellable
- Combine Operators & Pipelines — map, filter, debounce, combineLatest and receive(on:)
- Advanced Concurrency: async let, TaskGroup & Actors — Parallel async let, task groups, actors and @MainActor isolation
- Networking with URLSession & async/await — Fetch and decode JSON with URLSession.data(from:) and Codable
- Persistence with Core Data — Managed objects, contexts, fetch requests and @FetchRequest
- SwiftData Basics — @Model, ModelContainer and @Query — the modern persistence API
- Unit Testing with XCTest — XCTestCase, assertions, async tests and protocol-based mocking
- Swift Package Manager — Package.swift, dependencies, targets and adding packages
- App Architecture with MVVM — Model-View-ViewModel, observable view models and testable design
- Custom Property Wrappers — Build your own @propertyWrapper with wrappedValue and projectedValue
- The Swift Testing Framework — Modern testing with @Test, #expect, parameterized tests and suites
- Result Builders — How @resultBuilder powers SwiftUI's ViewBuilder — and write your own DSL
- Programmatic Navigation & Deep Linking — NavigationStack with a path, type-safe routes and onOpenURL deep links
- Swift Macros — Freestanding and attached macros, what they expand to, and SwiftSyntax
- Sendable & Data-Race Safety — Sendable, actor isolation, @MainActor and Swift 6 strict concurrency