SwiftUI Data Flow
with Redux
Thomas Ricouard (@Dimillian) - Glose and open
source stuff
Redux
• Is a design pattern

• To architecture your app data flow

• Centralize your application state

• And I love it!
But Redux????
• Single source of truth

• All business logic in one place

• Unidirectional data flow

• All state modification happen in reducers

• Easy to build isolated and reusable UI components
Redux data flow
Redux ♥ SwiftUI
Store conform to ObservableObject and our application state is wrapped in a
@Published property wrapper
Redux ♥ SwiftUI
We instantiate our Store with our AppState and inject it in our root view using
environmentObject view modifier
Redux ♥ SwiftUI
Our store is accessible in any view using @EnvironmentObject property wrapper
Redux ♥ SwiftUI
We can access our state to compute view properties or we can access it in
the body function directly
SwiftUI ♥ React
• Implementation here: https://github.com/Dimillian/
SwiftUIFlux

• You don’t access the store environmentObject directly

• You derivate your view properties from your state

• It’s cleaner + closer to modern React / Redux syntax
MovieSwiftUI
• I’ve made a real world and full open source SwiftUI +
Redux application.

• https://github.com/Dimillian/MovieSwiftUI
MovieSwiftUI
Custom redux
implementation
Now our app SceneDelegate is a bit more prettier
Custom redux
implementation
Because SwiftUIFlux have a StoreProvider built in (+ few other goodies)
ConnectedView
Receive new State
map(state) -> Props
body(props) -> some View
Dispatch action / State
modification
A simple view component
ConnectedView
ConnectedView
ConnectedView
How does it work?
How does it work?
How does it work?
How does it work?
How does it work?
How does it work?
How does it work?
Here is more!
One more component
One more component
One more component
Conclusion
• Easy separation of concern

• Work great with SwiftUI built-in data flow properties
wrappers and helpers

• View component are clean, small, reusable and empty of
business logic

• You can focus on your UI code, all business / models
bugs are in your reducers!
Thank you!
🚀

FrenchKit: SwiftUI Data Flow with Redux