This series aims to get you up and running with the RXSwift library. This amazing library enables you to “React” immediately to event changes. I’ve read many tutorials on this popular framework but really struggled to wrap my head around it. Only by experimenting have I truly understood it. So I’m going to try and teach you what I’ve learned in an easily digestible manner.
You’ll start with the basic features of RXSwift, and then slowly gear you up to the more advanced topics. I would strongly advise that you learn each section and then play with what your new found knowledge in your own project.
I really like Ray Wenderlichs definition of what RXSwift is and captures it in a way that as a developer, you will understand.
RxSwift, in its essence, simplifies developing asynchronous programs by allowing your code to react to new data and process it in sequential, isolated manner. Ray Wenderlich.
So what is asynchronous programming?
Asynchronous programming in simple terms allows your program or app to do many things at once. Similarly to multi-tasking.
To illustrate, when you are cooking a meal you don’t wait for each item to finish cooking before moving onto the next item. You gather all your ingredients, prep them and then cook them either in the oven, on the hob or in the microwave. You try and time it the best you can until all the ingredients are cooked and ready to serve. While serving you may decide to put a desert in the oven. Therefore the pudding will be ready for you to enjoy after that hearty main course.
Similarly, when it comes to computer programming your app may do the following things at the same time:
- playing audio files
- saving data
- downloading date
- reacting to user interactions
- and much more
Swift alone does a great job at allowing you to do many things at once using different threads and cores.
However, it struggles when two or more actions need to work with the same piece of data. It really can become complicated!
To help, Apple has provided many tools for us to work with that include
- Grand Central Dispatch
- Key Value Observations
- Notification Center
This is why it can get complex. You can be using a variety of API’s that Apple offers to deal with tasks asynchronously.
Some clever people at Microsoft took on the challenge of solving the problems of scalable, real-time application development thus came to fruition the framework we now know as RX (Reactive Extensions)
It proved so popular that it was quickly absorbed into other mainstream languages such as JS, Kotlin, Scala, and Swift. The logic is language agnostic thus you can talk to your fellow android developers about the principles and functions offered by RX.
Next, we will look at the foundations of RXSwift and what makes it tick!