BlaBlaCar Martin Moizard Jun 21, 2018

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

Critical Insight

A side effect free extension that transforms any Observable into separate data, loading, and error streams without compromising reactive principles.

The article includes the full implementation code you can drop directly into your RxSwift projects today.

About This Article

Problem

iOS developers using RxSwift often struggle to track loading states during async operations like network calls, image processing, and Core Location requests. The typical solutions push them toward imperative programming patterns that go against reactive principles.

Solution

Martin Moizard built a custom .monitorLoading() extension for ObservableType. It splits async operations into three streams: .data() returns results, .loading() tracks Boolean state, and .error() handles failures.

Impact

The extension keeps side effects out of the picture while preserving pure reactive streams. Developers can show or hide loaders without modifying external state or abandoning reactive programming.