Hide chapters

RxSwift: Reactive Programming with Swift

Fourth Edition · iOS 13 · Swift 5.1 · Xcode 11

“If you’ve ever used an asynchronous callback based API, you’ve probably dealt with handling the response data ad-hoc all across your codebase, and have most likely decided there was no way to unit test it all… But, let me tell you - there is a better way, and it’s called Rx!”

— Krunoslav Zaher, creator of RxSwift

There’s no denying it: Rx is one of the hottest topics in mobile app development these days!

If you visit international conferences, or even local meetups, it might feel like everyone is talking about observables, side effects, and (gulp) schedulers.

And no wonder — Rx is a multi-platform standard, so no matter if it’s a web development conference, local Android meetup, or a Swift workshop, you might end up joining a multi-platform discussion on Rx.

The RxSwift library (part of the larger family of Rx ports across platforms and languages) allows you to use your favorite Swift programming language in a completely new way. The somewhat difficult-to-handle asynchronous code in Swift becomes much easier and a lot saner to write with RxSwift.

To create responsive and robust applications, you have to handle a multitude of concurrent tasks like playing audio, handling user interface input, making networking calls, and more. Sometimes, passing data from one process to another or even just observing that tasks happen in the correct sequence one after another asynchronously might cause the developer a lot of trouble.

In this book, you’ll learn how RxSwift solves the issues related to asynchronous programming and master various reactive techniques, from observing simple data sequences, to combining and transforming asynchronous value streams, to designing the architecture and building production quality apps.

By the end of this book, you’ll have worked through the chapter content and you’ll have hands-on experience solving the challenges at the end of the chapters — and you’ll be well on your way to coming up with your own Rx patterns and solutions!

Who this book is for

This book is for iOS developers who already feel comfortable with iOS and Swift, and want to dive deep into development with RxSwift.

If you’re a complete beginner to iOS, we suggest you first read through the latest edition of the iOS Apprentice. That will give you a solid foundation of building iOS apps with Swift from the ground up but you might still need to learn more about intermediate level iOS development before you can work through all chapters in this book.

If you know the basics of iOS development but are new to Swift, we suggest you read through Swift Apprentice first, which goes through the features of Swift using playgrounds to teach the language.

You can find both of these books at our online store:

How to use this book

Generally, each chapter in this book includes a starter project and covers a small number of programming techniques in detail. Some of the chapters deal mostly with theory so you get to try isolated pieces of code, while learning the process in a Swift playground.

Other chapters provide you with a starter project that includes some non-Rx logic inside and lead you through Rx-ifying the project by adding code in key places. In the process, you’ll see what difference RxSwift makes in the project code and how to approach different common problems.

We do suggest that you work through the chapters in order, since the concepts build upon each other. Remember you’ll get the most out of the book if you follow along with the tutorials and perform the hands-on challenges.

For advanced developers, there’s still value in the early chapters since they cover the basics. However if you’re comfortable with those concepts, feel free to jump ahead to the topics that interest you the most.

What’s in store

This book is divided into six sections. You can find more details on each section in its introduction. Here’s a brief overview.

Section I: Getting Started with RxSwift

The first section of the book covers RxSwift basics. Don’t skip this section, as you will be required to have a good understanding of how and why things work in the following sections.

Section II: Operators and Best Practices

In this section, once you’ve mastered the basics, you will move on to building more complex Rx code by using operators. Operators allow you to chain and compose little pieces of functionality to build up complex logic.

Section III: iOS Apps with RxCocoa

Once you’ve mastered RxSwift’s basics and know how to use operators, you will move on to iOS specific APIs, which will allow you to use and integrate your RxSwift code with the existing iOS classes and UI controls.

Section IV: Intermediate RxSwift/RxCocoa

In this section, you will look into more topics like building an error-handling strategy for your app, handling your networking needs the reactive way, writing Rx tests, and more.

Section V: RxSwift Community Cookbook

Many of the available RxSwift-based libraries are created and maintained by the community – people just like you. In this section, we’ll look into a few of these projects and how you can use them in your own apps.

Section VI: Putting it All Together

This part of the book deals with app architecture and strategies for building production-quality, full-blown iOS applications. You will learn how to structure your project and explore a couple of different approaches to designing your data streams and the project navigation.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2024 Kodeco Inc.