Join Scott Gardner for an in-depth discussion in this video What is reactive programming?, part of Reactive Programming in iOS with RxSwift.
- Writing asynchronous and concurrent code in order to keep the main thread responsive to users is hard, but it's an essential task. To get it right takes an amazing amount of dedicated effort and that's just to understand one platform such as iOS. If you want to or need to develop for other platforms, those platforms' libraries and nuances are large unto themselves. As a result, cross-platform development tools have emerged, some of them good, but if you ask me developing native apps using native tools, nothing else feels better.
It's certainly how I do my best work. With all these considerations in mind, this is where reactive programming comes in. Reactive programming is at its essence about working with asynchronous streams or sequences of data. Everything else builds upon this concept. More specifically, reactive programming is about reacting to things coming from those sequences. So here we have a program sitting happily in its environment. Traditionally, we're used to explicitly interacting with the environment, fetching data for example.
In reactive programming, the environment asynchronously sends events, which the program can react to. This may already be starting to sound like notifications or delegate callbacks to you and if so, you're on the right track. Here's a pseudocode example. Traditionally if A is assigned a value of three and B four, then C is seven and even if A is then assigned a new value of six, C is still seven of course. Maybe you always want C to always reflect the current values of A and B added together though.
In reactive programming, if A and B are observable sequences with initial values of three and four and then C, also an observable sequence that combines and sums A and B, it'll have an initial value of seven. But if either A or B's value is updated, say a value of six is added onto A, C will reactively also be updated to 10 in this example. Now that I've gone over some fundamental concepts of reactive programming, I can get into reactive extensions, which implement reactive programming concepts.
Learn reactive programming with Reactive Extensions for Swift and iOS by following along with author Scott Gardner. Scott introduces the Reactive Extensions libraries for Swift and Cocoa Touch, and shows how to work with observable sequences, bind user interface and data elements, perform networking operations, debug Rx code, and more.
- Using the Reactive Extensions library
- Working with observable sequences
- Binding UI and data elements
- Binding table and collection views
- Error handling