iOS & Swift

Swift Apprentice: Beyond the Basics

“Swift Apprentice: Beyond the Basics” is a programming language guide that extends the fundamentals of Swift to cover broader topics like concurrency, memory management, and more. It presents the topics using interactive Swift playgrounds that you can follow along with. By Eli Ganim, Ehab Amer & Matt Galloway.

Read for Free with the Personal Plan* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99* *Includes access to all of our online reading features.
Leave a rating/review
Download materials
Buy paperback—Amazon Comments
Save for later
Share

Who is this for?

This book is designed for readers that have finished Swift Apprentice: Fundamentals or its equivalent and want to learn about more advanced language features.

Covered concepts

Core topics include such things as access control, code organization, testing, property wrappers, result builders, concurrency, value semantics, and memory management.

Swift Apprentice: Beyond the Basics is the sequel to Swift Apprentice: Fundamentals and explores additional Swift programming concepts. These topics include such things as access control, code organization, testing, property wrappers, result builders, concurrency, value semantics, and memory management, presenting them using interactive playgrounds that the reader can follow along...

more

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

Section I: Beyond the Basics

The section is a list of the expanded areas of Swift programming. It systematically navigates a variety of important topics, from the principles of Access Control, Code Organization, and Testing to custom Operators, Subscripts, and Keypaths. It presents in-depth coverage of Swift’s powerful idioms, like Result Builders and Pattern Matching, and ensures your proficiency in handling real-world errors.

The section further covers advanced concepts such as Encoding & Decoding Types, Memory Management, and takes you through the subtelties of value semantics. It presents a thorough discussion on Property Wrappers, the driving force behind popular frameworks like SwiftUI, and explores Protocol-Oriented Programming, underscoring Swift’s protocol-based design.

Finally, it covers Advanced Protocols, Generics, and Concurrency, giving you a solid understanding of Swift’s language-level concurrency mechanisms. Each topic provides a robust foundation for advanced Swift programming, ensuring your grasp of these concepts is both thorough and practical.

Swift gives you powerful tools for hiding complexity and organizing your code into easier-to-digest units. As your codebase grows, ensuring correctness with automated tests becomes more critical in your projects.
You’ll learn how to define your own operators and use subscripts to make your types feel even more like built-in language constructs. Keypaths provide references to properties, and together with subscripts and dynamic member lookup, you can do amazing things.
Toggle description
Swift is a concise, powerful language but can be verbose for certain tasks. Result builders allow you to create a domain-specific language and compactly express complex values. In this chapter, you will implement a result builder for making fancy attributed strings.
Toggle description
With pattern matching, you can accomplish more with less typing, and it helps give Swift its modern language feel. This chapter picks up where “Swift Apprentice: Fundamentals - Chapter 4: Advanced Flow Control” left off and shows you powerful Swift idioms that let you work with switch statements, tuples, optionals and more.
Toggle description
In the real world, you can’t avoid some errors. Gracefully handling errors is what sets mediocre code apart from great code. From handling missing values and simple initialization failure with optionals to providing greater diagnostic detail using full-featured error types, Swift provides language features to make your code robust and informative in the face of errors.
Toggle description
Swift has a powerful system for saving and loading your types to and from, for example, a file system, over the internet or some other communication channel. Swift has exceptional out-of-the-box support for the JSON format you will become familiar with in this chapter.
Toggle description
This chapter digs into the details of Swift's automatic reference counting and memory management. It shows you how to avoid memory leaks when object relationships result in reference cycles.
Toggle description
Value semantics have a clear advantage over reference semantics regarding local reasoning but can lead to inefficiency for large objects. This chapter shows you how to get the best of both worlds.
Toggle description
Used widely in frameworks like Apple’s SwiftUI and Vapor, property wrappers are a general-purpose language feature for building reusable, custom logic that defines how a property behaves. This chapter develops an advanced example and highlights some pitfalls to avoid.
Toggle description
From the standard library to user-authored generics, Swift is a protocol-based language. In this chapter, you’ll see how to get all of the benefits associated with object-oriented programming while being able to avoid most of the difficulties.
Toggle description
Learn how to use constraints to make generic code more useful and how to hide implementation details with type erasure and opaque return types.
Toggle description
Swift concurrency is a new way to handle asynchronous and concurrent code. It implements structured concurrency and provides language features that check many aspects of your code at compile time. You'll learn about these mechanisms and how actors protect the shared mutable state of your objects without needing a lot of error-prone, boilerplate code.