Search code examples
iosreactive-programmingrx-swiftrx-cocoa

In which situation good reason to use RxSwift & RxCocoa?


A few days ago I have begun to learn RxSwift and but the more I write code and can't understand which cases need to use reactive programming, I am can write the same code without RxSwift and use NotificaitionCenter, delegate pattern, Grand Central Dispatch, Closures.

I understand that RxSwif and RxCocoa give next opportunity:

There are some different ways to pass information from one object to another in iOS reactively (Notification, pass in closure, delegate, KVO, & target/action,) each of these different systems may be simple by itself but most of the complexity in the logic of an iOS app is in having to convert from one of these systems to another. RxSwift/RxCocoa replaces virtually all of these systems with one which is in a Rx way.

But when I am trying to write code on Rx I saw that this code not easy to understand.

Maybe someone can give examples of when need to use Rx inside the application or maybe in most cases doesn't need to use Rx because code will be complicated to understand, I am enjoyed from knowledge about Rx but not fully understand the good situation when need use it.


Solution

  • Well it's a tool like any other. Some people use it because you end up writing less code than you would otherwise. It does have a steep learning curve, but it can be valuable if a project requires it (the project already uses it, and the people involved want to continue using it).

    I worked for company that had an RxSwift project. All the architecture was built around RxSwift and all the code had to be written using RxSwift. The code was less complex than it would've been without using RxSwift. The major issue was that it was hard to onboard new developers on the project because as I said before the learning curve for Rx is pretty steep. In the end, for that reason, they decided to start moving away from Rx to a more classical approach.

    I also worked for companies that completely reject RxSwift because they don't want another 3rd party dependency in their app.

    So at the end of the day it's just a matter of preference. Personally I do see the benefits and conciseness of Rx, but prefer to use as little 3rd party dependencies as possible.

    To really get the benefits of Rx you'd have to use it intensely in a project and build your architecture around it. Unlike other 3rd party libraries you can't just put a wrapper around RxSwift in case it goes away and you decide to replace it with something else. But then again Rx is such wide-spread on all platforms and programming languages that I don't think it's going away any time soon.

    So long story short, use it and see if you like or not. And if not, at least it's good to know it if you happen to start working on someone else's project that uses it.