Black Friday — Promotion
Ends in ::
Get complete and immediate access to a Pro Yearly subscription with all benefits for just $399 for your first year — or lock in for two years for $599
Who is this for?
Combine uses a multitude of advanced Swift features such as generics, so you should have at least an intermediate-level knowledge of Swift.
- Reactive programming
- Combine operators
- Usage in real-world apps
- SwiftUI with Combine
- Error handling
- Custom publishers
Writing asynchronous code can be challenging, with a variety of possible interfaces to represent, perform, and consume asynchronous work — delegates, notification center, KVO, closures, etc. Juggling all of these different mechanisms can be somewhat overwhelming. Does it really have...more
Master declarative asynchronous programming with Swift using the Combine framework!
Writing asynchronous code can be challenging, with a variety of possible interfaces to represent, perform, and consume asynchronous work — delegates, notification center, KVO, closures, etc. Juggling all of these different mechanisms can be somewhat overwhelming. Does it really have to be this hard? Not anymore!
With Apple’s introduction of the Combine framework in WWDC 2019, it is clear that Apple aims to position declarative and reactive programming in Swift as a long-term investment and a game-changer in how developers perform and compose pieces of asynchronous work, making it a must-have tool at your disposal.
The introduction of Combine as a built-in framework in Apple’s ecosystem is promising news to developers who were interested in frameworks such as RxSwift or ReactiveSwift, but didn’t want the overhead of a third-party dependency; and while experience with either of the above could be useful, it is not a prerequisite for this book. You’ll learn everything from the ground up to become a true Combine master.
What Is Combine?
Combine is Apple’s framework to work with asynchronous events in a unified and reactive way that ensures your app is always up to date based on the latest state of its data.
What are these asynchronous events, you might ask? Anything that happens over time in your application can be represented by what is known as a Combine Publisher — network requests, user input, notifications, KVO, and much more. And since Combine unifies all of these different mechanisms under a single interface, this opens the door to interesting and powerful ways of composing logic and work in a declarative and universal way.
Combine is also tightly integrated throughout Apple’s SDKs. For example, the UI framework SwiftUI uses Combine to ensure your app’s views stay up to date, which makes Combine a must-have for your skillset.
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: Introduction to Combine
In this part of the book, you’re going to ramp up over the basics of Combine and learn about some of the building blocks it comprises. You’ll learn what Combine aims to solve and what are some of the abstractions it provides to help you solve them: Publisher, Subscriber, Subscription, Subject and much more.
Section II: Operators
If you think of Combine as a language, such as the English language, operators are its words. The more operators you know, the better you can articulate your intention and the logic of your app. Operators are a huge part of the Combine ecosystem which lets you manipulate values emitted from upstream publishers in meaningful and logical ways.
In this section, you’ll learn the majority of operators Combine has to offer, divided into useful groups: transforming, filtering, combining, time manipulation and sequence. Once you’ve got your operator chops down, you’ll wrap up this section with a hands-on project to practice your newly-acquired knowledge.
Section III: Combine in Action
You now know most of Combine’s basics. You learned how publishers, subscribers and subscriptions work and the intertwined relationship between these pieces, as well as how you can use operators to manipulate publishers and their emissions.
While theory is great and definitely useful, practical real-life knowledge is king!
This section is divided into five mini-chapters, each with its own focus on practical approaches for leveraging Combine for specific use-cases. You’ll learn how to leverage Combine for networking, how to debug your combine publishers, how to use timers and observe KVO-compliant objects, as well as learn how resources work in Combine.
To wrap up this section, you’ll get your hands dirty and build an entire Combine-backed network layer — how exciting!
Section IV: Advanced Combine
With a huge portion of Combine foundations already in your tool belt, it’s time to learn some of the more advanced concepts and topics Combine has to offer on your way to true mastery.
You’ll start by learning how to use SwiftUI with Combine to build truly reactive and fluent UI experiences and switch to learn how to properly handle errors in your Combine apps. You’ll then learn about schedulers, the core concept behind scheduling work in different execution contexts and follow up with how you can create your own custom publishers and handling the demand of subscribers by understanding backpressure.
Finally, having a slick code base is great, but it doesn’t help much if it’s not well tested, so you’ll wrap up this section by learning how to properly test your new Combine code.
Section V: Building a Complete App
Mastery takes practice, and practice you shall!
You’ve made it through this entire book, an amazing feat by all means. It’s time to truly solidify the knowledge you’ve acquired throughout this chapter and build an entire app using Combine and SwiftUI.