Learn To Code Using Swift
Learn To Code Using Swift is a programming book for absolute beginners, born from a fresh approach. It promises beginner-friendly explanations even for complex topics and provides up-to-date Swift knowledge. The book builds progressively from the basics to advanced concepts without expecting any prior programming experience — it clearly explains every idea, definition, and code snippet. It also teaches algorithmic thinking and reasoning skills necessary to thrive even in the age of LLMs. Theory and practice go hand in hand, with more than 350 exercises included to build confidence and solid foundations. Most of the modern Swift language features are covered, making this book a great base for anyone regardless of specific platform or interest.
Now Available: Beta Release
- Get early access to the first 14 chapters of the book today.
- Chapters 15 (Concurrency) and 16 (Attributes) are in progress and coming soon.
- By joining the beta, you’ll also receive the final, fully polished edition at no extra cost.
- Content is evolving — exercises, projects, and chapters may change as we refine and improve during the beta.
- Beta bonus: During the beta period, you’ll get free help directly from the writers on Discord — ask questions, share progress, and get answers faster.
Book overview
Preface: Getting Started - This chapter introduces the fundamentals needed to begin programming with Swift. It covers the basics of programming concepts, an overview of the Swift language, and how to use the command line. It also explains Integrated Development Environments (IDEs) and how to choose and set up your development environment.
Lessons:
- Introduction
- Command line
- Swift
- Programming
- IDE
Chapter 1: The basics - This chapter covers the core building blocks of Swift programming. It explains how to use the print function, write comments, and define constants and variables. It introduces Swift’s standard data types and demonstrates common string operations, including string interpolation.
Lessons:
- The print function
- Comments
- Constants & variables
- Standard types
- String operations
Chapter 2: Operators - This chapter provides a detailed overview of Swift’s operators and how they are used in programming. It covers the assignment operator, arithmetic operators, and the remainder operator. It explains comparison and logical operators, as well as how to combine operators to create more complex expressions.
Lessons:
- Assignment operator
- Arithmetic operators
- Remainder operator
- Comparison operators
- Logical operators
- Combining operators
Chapter 3: Optionals - This chapter introduces optionals and their role in handling situations where data may be missing or invalid. It explains how to read user input with the readLine function and why the returned value is optional. It covers the nil value, working safely with optionals, and writing programs that respond appropriately to user input.
Lessons:
- The nil value
- The readLine function
Chapter 4: Data types - This chapter explores Swift’s data types beyond the basic single-value types. It covers ranges, arrays, sets, and dictionaries, explaining how and when to use each. It also introduces specialized types such as UInt, Float, and Character for more precise data control.
Lessons:
- Ranges
- Arrays
- Sets
- Dictionaries
- Other types
Chapter 5: Control flow - This chapter explains how to use control flow to make decisions and repeat actions in Swift programs. It covers conditional statements (if-else and switch-case), looping structures (while, repeat-while, and for-in), and the concept of variable scope. It also introduces nested statements for more complex logic.
Lessons:
- If-else
- Switch-case
- While
- Repeat-while
- For-in
- Scopes
- Nested statements
Chapter 6: Functions - This chapter introduces functions as a way to organize and reuse code in Swift. It covers defining and calling functions, working with parameters and return values, and understanding function types. It also explains closures and higher-order functions for more advanced use cases.
Lessons:
- Basics
- Parameters
- Return types
- Closures
- Higher-order functions
Chapter 7: Structs - This chapter introduces structs as a way to create custom data types in Swift. It explains how to define structs, create and use instances, and add properties to store data. It also covers writing methods to give structs behavior and shows how they can help organize code.
Lessons:
- Basics
- Initialization
- Properties
- Methods
Chapter 8: Enums - This chapter explains how to use enums to define types with a limited set of possible values. It covers basic enum syntax, adding associated values, and using raw values. It also shows how to add methods and properties to enums and use pattern matching for more expressive logic.
Lessons:
- Basics
- Case values
- Methods and properties
- Pattern matching
Chapter 9: Error handling - This chapter introduces Swift’s error handling system and how to model errors using structs and enums. It covers writing functions that can throw errors and handling them with do, try, and catch. The chapter also explains using guard-else, the Result type, and runtime checks to write safer, more reliable code.
Lessons:
- Error types
- Do-catch
- Throwing functions
- Guard-else
- The Result type
- Runtime checks
Chapter 10: Packages - This chapter covers how to organize and manage Swift code using packages and package managers. It explains creating executables and libraries, managing access control, and writing tests. It also introduces version control, handling dependencies, and essential tools for real-world project development.
Lessons:
- Basics
- Executables
- Access control
- Libraries
- Tests
- Version control
- Dependencies
- Tools
Chapter 11: Protocols - This chapter introduces protocols as a way to define shared capabilities that different types can adopt. It covers how to define protocols, make types conform to them, and write flexible, reusable code based on behavior rather than concrete types. The chapter also explores protocol inheritance, extensions, associated types, and built-in protocols.
Lessons:
- Basics
- Extensions
- Inheritance
- Associated types
- Built in protocols
Chapter 12: Generics - This chapter explains how to use generics to write flexible, reusable, and type-safe code. It covers creating generic functions, types, and protocols, allowing your code to work with different data types without duplication. The chapter also introduces variadic generics for advanced use cases.
Lessons:
- Functions
- Types
- Protocols
- Variadics
Chapter 13: Classes - This chapter focuses on classes — reference types that let multiple variables share and modify the same instance, making them a core tool for modeling shared state. It also explores related object-oriented programming features like inheritance and polymorphism, while also introducing considerations around memory management such as reference counting and potential retain cycles.
Lessons:
- Basics
- OOP
- Memory management
Chapter 14: Ownership - This chapter explores Swift’s ownership model, explaining how memory is managed and how value ownership affects mutation and access. It covers concepts like non-copyable types, ownership modifiers, and working with unsafe memory.
Lessons:
- Basics
- Non-Copyable
- Modifiers
- Unsafe memory
🔨 Chapter 15: Concurrency - This chapter introduces concurrency in Swift, covering the fundamentals of asynchronous programming. It explains how to use async-await, manage tasks, and ensure safe data access with actors and the Sendable protocol. The chapter also covers asynchronous sequences.
Lessons:
- Basics
- Async-await
- Tasks
- Sendable
- Actors
- Sequences
🔨 Chapter 16: Attributes - This chapter covers advanced Swift features that enhance code expressiveness and performance. It introduces attributes, property wrappers, and key paths to write cleaner and more powerful code. It also explores modern concepts like result builders, macros, and other more advanced attributes.
Lessons:
- Result builders
- Macros
- Others
✅ Regular updates for FREE
Source materials will receive regular updates as the Swift language evolves. If you buy one of the editions above, you'll get access to these updates for FREE. We're planning to release quarterly updates. We'll keep the book and all the source materials up-to-date for years. This means that purchase includes FREE updates for a very long time.
🤔 Do you have any questions?
Feel free to send us your thoughts so we can improve both the samples and the book.
Please don't hesitate to contact us using the options below.
Contact details
- Web: learntocodeusingswift.com, learn-swift.com
- Email: learntocodeusingswift@gmail.com
- Social: @tiborbodecs, @kittibodecs
---
I hope you'll enjoy reading our book.
Thank you for your support. 🙏
During the beta period, you’ll receive a digital copy of the book in PDF format. After the final release, we’ll provide more formats, such as web and epub.