RxSwift Observable Loading State Management
Article Summary
Martin Moizard from BlaBlaCar tackles a common RxSwift pain point: how do you elegantly track loading states without breaking reactive programming principles?
When building iOS apps with RxSwift, displaying loaders during async operations (network calls, image processing, location services) often forces developers into imperative patterns or side effects. Moizard presents a cleaner approach that keeps your code purely reactive.
Key Takeaways
- Traditional .do() operator approach works but introduces unwanted side effects
- Custom .monitorLoading() extension splits streams into .data(), .loading(), and .error()
- Solution eliminates side effects while maintaining reactive programming philosophy
- Provides clean API for handling loading states and errors separately
Critical Insight
A side effect free extension that transforms any Observable into separate data, loading, and error streams without compromising reactive principles.