Best Practices with Unidirectional Data Flow on iOS

Last updated: 20 days ago

Flux/Redux/MVU state management architectures have been discussed a lot recently in the iOS community, and many developers are adopting unidirectional data flow to power the interfaces they build. Since we adopted Flux around 5 years ago to power state management in our production app (used by thousands of customers every day), we’ve learned a lot about do’s, don’ts, best practices, code smells, and how to structure our code to allow us to iterate quickly and effectively using this architecture.

In this talk, we’ll introduce our flavor of Flux and do a deep dive into the “real world” issues we’ve run into and the solutions we developed for them:

  • How to interoperate with Objective-C while writing your Flux stores in Swift
  • How we use multiple stores and centralized dispatch to make working with Flux as easy as possible
  • How to structure UIKit and SwiftUI views/controllers to ensure reusability while still powering them with one-way data flow
  • Integrating with the trickier imperative parts of UIKit, like UINavigationController and popovers
  • How we break our code into units to ensure easy testability, and our best practices for testing unidirectional code
  • How to identify code smells in your Flux architecture, with real world examples from our codebase

Hopefully you’ll come away with a better understanding of unidirectional data flow and what might be involved in implementing it in your real-world iOS apps.