Swift
From optionals, value types and protocols to strict concurrency, SwiftUI, Core Data, app architecture and on-device machine learning, Swift as told through the free samples of Leanpub books.
Created from the free samples of 14 Leanpub books and the descriptions and tables of contents of 12 more, with every source cited.
Swift is a compiled, statically typed programming language created to replace Objective-C as the main language for software on the iPhone, the Mac and their sibling devices. It was designed for safety, performance and expressiveness: the type system rules out whole classes of error before a program runs, the compiler produces native machine code through the LLVM infrastructure, and the syntax keeps the distance short between what a programmer means and what the code says.[2][1] It supports procedural, object-oriented, protocol-oriented and functional styles in one language.[1]
Swift was announced in 2014 and released as open source at the end of 2015, and it has since been used for server software, command-line tools and code on Linux, Windows and Android as well as on the platforms it was made for.[1] Most of the books in this article nonetheless treat it where most Swift is written, in apps for iOS and macOS, and so they are as much about frameworks (the interface toolkits, the persistence layer, the machine learning libraries) as about the language. One of them draws the line explicitly: Swift is the language, and SwiftUI, UIKit and Foundation are frameworks used from it.[1]
This article covers the language's history and design, its central ideas, concurrency, the interface frameworks, persistence, app architecture, engineering practice, on-device machine learning, and learning and interview preparation. Its sources are the free samples of fourteen Leanpub books and the descriptions and tables of contents of twelve more, published between 2016 and 2026. Swift changed quickly in its first years, so the books from 2016 and 2017 show syntax from Swift 2 to Swift 4; each book carries its year, and the older ones are cited for ideas that have lasted.
Where to start
Readers who have never programmed have two books written for them. The Swift Codebook (2024) assumes no programming experience and teaches the language itself, based on Swift 5.10, with stories and analogies in place of jargon.[13] Learn Swift Programming by Examples (2019) teaches programming through graded exercises written in Swift, on a method its author borrowed from the teaching of spoken languages: each exercise extends a familiar one by a few new elements.[12]
A programmer coming from another language can start with Swift Programming: From Fundamentals to Mastery (2026), which runs from variables to generics and concurrency and is checked against the current release, or with Building macOS Applications with Swift (2026), which begins with the syntax and ends with a shipped Mac application.[1][2] SWIFT - Quick Start (2021) is a set of short standalone tutorials, one feature each, with a summary chapter for reference.[14] Your First Swift App (2016) builds one small iOS app chapter by chapter and assumes some object-oriented programming; its Swift and its tools are of that year.[11]
Several books are explicitly not first books. Swifter - 100 must know tips for Swift (2016) is a hundred short tips for readers who have finished an introduction and stalled at their first real project.[10] iOS Development with Swift 6 (2026) is for senior engineers who maintain large production apps and does not explain what a struct is.[3] Swift Programming for Advanced Developers (2026) addresses developers who already know the language.[16] Mastering MVVM With Swift (2017) and Mastering Core Data With Swift (2017) each take a working Swift developer through one subject by building or refactoring one app.[5][6]
History
Before Swift, software for these platforms was written in Objective-C, an extension of C with message passing in the style of Smalltalk. By 2010 it showed its age: verbose syntax, a weak type system, crashes from null pointers and memory management that was easy to get wrong.[2][1] Work on a successor began that year as one engineer's project, by the creator of the LLVM compiler infrastructure, and a small team had joined by late 2011.[2] The language drew on many others, among them Objective-C, Rust, Haskell, Ruby, Python and C#.[1][2]
It was unveiled in June 2014 at the company's annual developer conference, having been kept secret from nearly everyone outside it.[2] In December 2015 it was released as open source under the Apache 2.0 licence, and changes to the language have since gone through a public proposal process.[2] The same book summarises the releases: Swift 2 added error handling, Swift 3 a more consistent interface style, Swift 5 a stable binary interface, Swift 5.5 the modern concurrency features, and Swift 6, in September 2024, compile-time checking for data races.[2] The books of late 2026 target Swift 6.4.[1][3]
The early years were turbulent for readers and authors alike. A 2016 book warns that its code runs under Swift 2 and may need changes for later versions, and a 2017 book describes the language as still very young, with developers working out how best to use it.[10][15]
The language
Swift prefers things that do not change. A constant is declared with let and a variable with var, and the convention is the reverse of most languages: immutability is the default habit and mutability is what has to be asked for.[1] Every value has a type known at compile time, though the compiler usually infers it from the initial value, so annotations are needed mainly where there is no value to infer from.[1] Nothing is converted silently. A number of one type must be converted explicitly to another, a condition must be a real Boolean, and integer arithmetic that overflows stops the program instead of wrapping round.[1] Strings are Unicode throughout, and a character is what a reader perceives as one, even when it takes several code points to encode.[1]
Optionals
The feature the books single out is the optional, a type that either holds a value or holds nothing. Because the possibility of absence is part of the type, the compiler makes the programmer deal with it, which removes the null-pointer crash familiar from C-based languages.[2][1] An interview guide lists the ways of handling one: binding it to a name inside a condition, chaining calls that quietly yield nothing if any link is absent, supplying a default, and forced unwrapping, which crashes when the value is missing and is to be avoided unless its presence is certain.[8] Optionals are also what newcomers find hardest. One author describes finishing the official tutorial, opening a real project and having to stop to recall when an optional is wanted and when it is not.[10]
Value types, reference types and protocols
Structures and enumerations are value types: assigning one or passing it to a function copies it, so a change to the copy leaves the original alone. Classes and closures are reference types, and every reference sees a change made through any of them.[8] The standard library is built on value types; strings, arrays, dictionaries and sets are all values, unlike their counterparts in the older frameworks, and copying is made cheap by deferring the actual copy until one side is modified.[4][1]
Value types cannot inherit from one another, which developers arriving from Objective-C often take for a missing feature. One book's advice to them is to unlearn what they know and start with an open mind, since the two languages differ more than they resemble each other and translating old habits into Swift leads to frustration.[4] Swift's answer to the absence of inheritance is the protocol, a description of what a type can do that any structure, enumeration or class may adopt, and the same book calls protocols and value types a more potent combination than classes and inheritance.[4] Classes remain necessary all the same, because the older frameworks are built on them.[4] A short 2017 book counts the choice between value and reference types among the four patterns its author uses in every project.[15]
Memory and closures
Memory is managed by automatic reference counting, with no garbage collector and no manual release calls.[2] The cost is that two objects holding strong references to each other are never freed. This arises most often with closures, self-contained blocks of code that capture the variables around them, and the remedy is a capture list declaring a reference weak or unowned.[8] The topic stays on interview lists at every level of seniority.[8]
Concurrency
Swift 5.5 introduced asynchronous functions and actors, and Swift 6 made the checking of concurrent code strict.[2] iOS Development with Swift 6 calls this the largest safety improvement in the language's history. Before it, the compiler warned about possible data races and compiled the program anyway, and the races surfaced as crashes that appeared only under particular timing, for some users, and could hardly be reproduced in testing.[3] Under the Swift 6 language mode they are compile-time errors.[3]
The model has three parts. Every piece of mutable state belongs to one actor, and code outside the actor must wait its turn to reach that state. A value may cross from one actor to another only if its type is marked as safe to send, which value types made of sendable parts are automatically. And the compiler tracks where values flow within a function, so that many values need no annotation at all.[3]
Moving an existing codebase is described as a project in its own right. The recommended route is incremental: turn the checks on as warnings, fix shared mutable state first, migrate module by module starting with the easiest, and switch the language mode last. The book cites one migration of three million lines that took about four hundred hours of engineering over six weeks, most of it spent on restructuring and not on annotations.[3] The language has escape hatches that tell the compiler to trust the programmer, and the book's rule for them is to document the reasoning, keep them few and verify with the thread sanitiser.[3]
Building interfaces
Three interface frameworks appear in the books. UIKit is the original toolkit for iOS, and AppKit its older counterpart on the Mac, still maintained; both are object-oriented and written for Objective-C. SwiftUI, introduced in 2019, is declarative: the code describes what the interface should look like for a given state, and the framework works out the changes.[2]
The older books show UIKit as it was taught. Your First Swift App builds a timer app from the single-view project template, reads the generated application delegate line by line and lays out screens in a storyboard, and its explanation of why framework classes carry two-letter prefixes (Objective-C had no namespaces) is still the reason those names look as they do.[11] The 2026 book for senior engineers has chapters on SwiftUI architecture and on making UIKit and SwiftUI work together, the state in which many production apps live.[3]
SwiftUI has its own shelf. macOS App Development: The SwiftUI Way (2024) builds four small Mac apps and then covers preparing a release and distributing through the store or independently.[17] SWIFTUI - Quick Start (2021) is a set of standalone tutorials on the framework's views, modifiers and property wrappers.[18] Mastering NavigationPath Handling in SwiftUI is a short guide to one part of it, navigation: saving and restoring the navigation state, deep links and multiple windows.[19] These three are cited from their descriptions.
On the Mac, shipping is part of the subject. An application is expected to be signed and notarised before the system will run it, one distributed through the store must run in a sandbox that limits its access to the system and the user's data, and builds should run natively on both processor families the Mac has used.[2]
Storing data
Core Data is the long-established persistence framework, on the Mac since 2005 and on iOS since 2009. Mastering Core Data With Swift insists first on what it is not. It is not a database, and the question of whether to use it or SQLite is the wrong question: Core Data manages a graph of objects, their life cycle, their relationships, validation and change tracking, and writing that graph to disk is an optional feature.[6] The book is as direct about the drawbacks. Core Data works only on objects it has loaded into memory, so deleting thousands of records means loading them first, and it expects to be used from a single thread, which makes concurrency a topic nobody working with it can skip.[6] For a handful of unrelated objects it recommends something lighter.[6]
SwiftData is the newer framework, built on Core Data and using Swift macros to simplify the declaration of models and queries.[2] Mastering SwiftData by Example in SwiftUI & iOS 18 (2024) teaches it together with SwiftUI; it has no sample and a two-sentence description.[20]
App architecture
The default pattern of the older frameworks is Model-View-Controller, and Mastering MVVM With Swift explains both its appeal and its failure. The appeal is a clear separation: the model holds the data and the business logic, views display without understanding what they display, and a controller connects the two. The failure is that whatever belongs to neither model nor view, the formatting of a date for the user's locale, say, lands in the controller, until after thousands of lines the controllers are overweight and impossible to test.[5] Model-View-ViewModel moves that work into a view model, a plain object that can be tested without the interface, and connects it to the view with bindings; the book refactors a weather app from one pattern to the other and writes the tests.[5]
Bindings lead to reactive programming. ReactiveCocoa Book (2017) teaches one family of reactive frameworks through its central idea, the signal: a stream that delivers value events over time and ends with exactly one of three terminating events, for completion, failure or interruption.[9]
Later books widen the choice. iOS Development with Swift 6 declines to name a best architecture: MVVM serves small and medium apps with straightforward state, Clean Architecture suits long-lived products with complex business rules, and the decision depends on team size, complexity and the failures a team most wants to prevent.[3] Clean Architecture in iOS (2022) applies the second of those, with layers, ports and adapters; its author says most of it holds for Android as well.[21]
Past a certain team size the question becomes one of modules. Modular Architecture on iOS and macOS (2024) starts from what happens when ten or more developers share one monolithic project: conflicting edits to the same project and interface files, long builds, and no good answer when the business asks for a second app from the same code. Its remedy is to split the app into frameworks owned by teams, arranged in five layers (application, domain, service, core and shared), and it is candid that maintaining such a foundation can be the work of a team of its own.[7]
Engineering practice
The Missing Manual for Swift Development (2017) is about what surrounds the code, and its chapter on security has dated least. Its premise is modest: a determined attacker will get at data on a device, so the aim is to make it hard, in layers. Credentials go in the keychain and never in the user defaults database. Network connections are encrypted, with certificate pinning where interception is a concern. Keys shipped inside an app can be extracted, least of all safely from its property list, and the stronger design has the app fetch credentials from a service when it needs them.[4] It adds two cautions that are easily forgotten: print statements still write to the console in production, and a third-party library whose source cannot be read may be sending away data the developer knows nothing about.[4] The author holds that telling a client about such risks is part of the developer's job, whoever makes the final decision.[4]
The 2026 book for senior engineers carries the theme into its later chapters on modularisation with the language's package manager, networking, security, testing, performance and delivery pipelines, which its sample lists and does not include.[3]
Machine learning on the device
The newest group of books is about running models on the user's own hardware, and all of it is cited from descriptions, since none has a sample. Four volumes of one series published in 2026 cover the ground. Core ML & Vision Framework with Swift. treats image analysis: classification, object and face detection, document scanning and the integration of custom models.[22] Apple Intelligence & Foundation Models. Building apps with Apple's on-device LLM APIs, Writing Tools, and the Apple Intelligence framework covers the system's built-in language models, the interfaces that expose an app's actions to the voice assistant, and the division of work between models on the device and a private cloud.[23] MLX Swift & Local LLMs. Deep dive into Apple's MLX framework for high-performance machine learning. covers running, quantising and fine-tuning open language models locally with an array framework built for the platform's processors.[24] visionOS & Spatial AI with Swift applies the same tools to a spatial computing headset, with hand and eye tracking and an understanding of the room.[25] The descriptions are promotional and give no means of judging depth.
Practice and interviews
Several books exist to be worked through and not read. Learn Swift Programming by Examples keeps its exercises simple on purpose, its author holding that learning to think in programs matters more than any one language, and puts the solutions in an appendix.[12] Swifter - 100 must know tips for Swift can be opened at any of its hundred tips, which run from pattern matching to interoperation with Objective-C and C.[10] Learn Swift Data Structures & Algorithms Visually - Volume 1 (2026) presents more than a hundred interview algorithms on trees, lists, strings and arrays, each with Swift code and a step-by-step visual trace; it is the first of four volumes.[26]
The iOS Interview Blueprint: Elite Edition (2026) , From Junior to Engineering Manager (2026) arranges interview questions by career level, from junior developer to engineering manager, and expects answers with structure: a definition, the trade-offs, an example from experience.[8] Its fundamentals section is a compact review of the language, and its advice on preparing with AI tools ends on accountability: an assistant can generate practice questions and mock interviews, and it also produces confident wrong answers about threading, so the engineer remains responsible for what is said in the room and for what is merged.[8]
Questions about Swift
Which Swift book should I start with?
A reader who has never programmed can start with The Swift Codebook (2024), which assumes no experience and teaches the language itself.[13] A programmer coming from another language can start with Swift Programming: From Fundamentals to Mastery (2026), which runs from variables to concurrency.[1] A reader who wants a Mac app at the end can start with Building macOS Applications with Swift (2026).[2]
What is an optional in Swift?
What is the difference between a struct and a class in Swift?
A struct is a value type: assigning or passing it makes a copy, and changes to the copy do not affect the original.[8] A class is a reference type, so every reference points to the same instance and sees its changes; classes support inheritance and structs do not.[8] The standard library's strings, arrays and dictionaries are value types.[4]
What changed in Swift 6?
Is Core Data a database?
Should I use MVC or MVVM in an iOS app?
Model-View-Controller separates concerns clearly but tends to collect everything that fits neither model nor view in the controllers, which grow large and hard to test.[5] Model-View-ViewModel moves that work into view models that can be tested without the interface.[5] One 2026 source finds MVVM suited to small and medium apps and prefers other architectures for products with complex business rules.[3]
Sources
Every source is a Leanpub book or course. The note after each says which part of it was read; where no sample was available, only the public description and table of contents were used.
- 1.Swift Programming: From Fundamentals to Mastery, Steve Publications: A Complete Guide to Modern Swift Development Free sample: the introduction on the language's history, design principles and neighbours, chapter 1 on values and types, and the opening of chapter 2. 2026. Free sample: PDF · EPUB
- 2.Building macOS Applications with Swift, Steve Publications: From First Program to Production Application Free sample: part of chapter 1 on the language's history and design, the Mac platform, its frameworks and the toolchain. 2026. Free sample: PDF · EPUB
- 3.iOS Development with Swift 6, Steve Publications: Building Scalable, Maintainable Applications on iOS 27 and the Modern Apple Platform Free sample: the introduction and chapter 1 on strict concurrency, isolation, migration and the escape hatches. 2026. Free sample: PDF · EPUB
- 4.The Missing Manual for Swift Development, Bart Jacobs Free sample: the chapters on security and on learning Swift with an open mind, and the opening of the next. 2017. Free sample: PDF · EPUB
- 5.Mastering MVVM With Swift, Bart Jacobs Free sample: the welcome, the chapters on the shortcomings of Model-View-Controller and on how Model-View-ViewModel works, and the opening of the sample app's tour. 2017. Free sample: PDF · EPUB
- 6.Mastering Core Data With Swift, Bart Jacobs Free sample: the welcome, the chapter on what Core Data is and is not, the sample app and the opening of the chapter on the Core Data stack. 2017. Free sample: PDF · EPUB
- 7.Modular Architecture on iOS and macOS, Cyril Cermak: Building large scalable iOS and macOS apps and frameworks with Domain Driven Design Free sample: the introduction and the chapter on modular design and its five layers. 2024. Free sample: PDF · EPUB
- 8.The iOS Interview Blueprint: Elite Edition (2026) , From Junior to Engineering Manager, Mike Salari: PREPARE. PERFORM. SUCCEED. Free sample: the introduction and the opening of the junior-level chapter on value and reference types, optionals, closures and memory. 2026. Free sample: PDF
- 9.ReactiveCocoa Book, Eimantas Vaičiūnas: Streams of values over time. Free sample: the overview of the frameworks and the opening of the chapter on signals and events. 2017. Free sample: PDF · EPUB
- 10.Swifter - 100 must know tips for Swift, Wei Wang Free sample: the introduction and the first tips. 2016. Free sample: PDF
- 11.Your First Swift App, Ash Furrow: Everything you need to know to build and submit your first iOS app. Free sample: part of chapter 1 on creating a project and reading the application delegate. 2016. Free sample: PDF · EPUB
- 12.Learn Swift Programming by Examples, Zhimin Zhan Free sample: the preface on the teaching method and the opening of chapter 1. 2019. Free sample: PDF · EPUB
- 13.The Swift Codebook, Grace Huang: A Beginner's Guide from Basics to Best Practices Free sample: the introduction. 2024. Free sample: PDF · EPUB
- 14.SWIFT - Quick Start, Ivor Online: Version: 1.0 - Date: 04.2021 Free sample: the notes on how to use the book and some of the first tutorials. 2021. Free sample: PDF
- 15.Learn the Four Swift Patterns I Swear By, Bart Jacobs No sample: from the description and table of contents. 2017.
- 16.
- 17.macOS App Development: The SwiftUI Way, Grace Huang No sample: from the description and table of contents. 2024.
- 18.SWIFTUI - Quick Start, Ivor Online: Version: 2.0 - Date: 04.2021 The sample could not be downloaded: from the description and table of contents. 2021. Free sample: PDF
- 19.Mastering NavigationPath Handling in SwiftUI, Robert Nash: A guide to navigating view hierarchies in SwiftUI No sample: from the description and table of contents.
- 20.Mastering SwiftData by Example in SwiftUI & iOS 18, DevTechie No sample: from the description. 2024.
- 21.Clean Architecture in iOS, Yair Carreno: Principles and good design practices applied in iOS. No sample: from the description and table of contents. 2022.
- 22.Core ML & Vision Framework with Swift., Edgar Milvus: On-device image classification, object detection, and custom model integration with Core ML and Vision. No sample: from the description. 2026.
- 23.Apple Intelligence & Foundation Models. Building apps with Apple's on-device LLM APIs, Writing Tools, and the Apple Intelligence framework, Edgar Milvus No sample: from the description. 2026.
- 24.MLX Swift & Local LLMs. Deep dive into Apple's MLX framework for high-performance machine learning., Edgar Milvus: Building custom inference engines, fine-tuning local models (LoRA), and leveraging Unified Memory directly from Swift. No sample: from the description, which outlines the chapters. 2026.
- 25.
- 26.Learn Swift Data Structures & Algorithms Visually - Volume 1, Flannan P. Brody: Data Structures & Algorithms for AI-Era Interviews The sample holds no readable text: from the description. 2026. Free sample: PDF
Further reading
Other books in the library on the same ground, not cited above.
- Mastering Mobile Application Development - 2nd Edition, Jonathan Engelsma, Hans Dulimarta: Learning iOS and Android Side-By-Side A textbook that teaches iOS and Android development side by side through one sample app. 2021. Free sample: PDF
- Mobile Coding Interviews Using Kotlin/Swift, Mahmoud Ramadan: Pattern-Based Problem Solving in Swift & Kotlin Coding interview patterns for mobile developers, with templates in Swift and Kotlin. 2026.
- Native Mobile Development After React Native, Steve Publications: Architecture, Engineering, and the Future of Platform-Native Apps How the native iOS and Android platforms work, for teams reconsidering a cross-platform framework. 2026. Free sample: PDF · EPUB
- iOS Accessibility Handbook, Luis Abreu: A clear, concise and complete reference. Accessibility guidelines adapted to iOS, with a reference to the platform's accessibility interface. 2016. Free sample: PDF · EPUB
- The Clean Way to Use Rx, Yair Carreno: Guide manual and tips for implementing with Rx extensions. Thirty-five rules for writing reactive code, with examples in Swift and equivalents on other platforms. 2020. Free sample: PDF · EPUB
- SwiftUI for AI Apps. Building reactive, intelligent interfaces that respond to model outputs, stream tokens, and visualize AI predictions in real time, Edgar Milvus SwiftUI interfaces for apps built around model output, with streaming and state management. 2026.
- CoreData, CloudKit & Vector Search, Edgar Milvus Storing and searching vector embeddings in an app's data layer and syncing them between devices. 2026.
- Building macOS Apps With SwiftUI, Grace Huang: A Practical Learning Guide A practical guide to building and releasing Mac apps with SwiftUI. 2023.