Hi iOS Developers,
I guess you must have heard about Apple announcing the Reactive Programming (aka Rx) framework called Combine. Therefore, Reactive Programming has become a very oriented topic for iOS development. Today, we are going to talk about the biggest Rx library for iOS — RxSwift.
What is RxSwift?
Rx is a generic abstraction of computation expressed through
Observable<Element>
interface.
by https://github.com/ReactiveX/RxSwift
Why RxSwift?
If your application reacts a lot to user integrations, RxSwift is here to clean up your massive codebase. Let’s take a look at an example of what does it look like with RxSwift.
Example:
Let’s say you are building a “like” feature that allows users to like posts. And you want to update the UI correspondingly.
Without RxSwift:
var isLiked: Bool = false {
didSet {
updateUI()
}
}
With RxSwift:
let isLiked = Variable(false) isLiked.asObservable().subscribe(onNext: {
updateUI()
})
let’s say you have a huge block of code inside the updateUI function. For example, you’d only want…