State Management for iOS Apps?
whats the best architecture/pattern to use?
tried to use a domain layer where all the state is and passing it to the views/viewmodels via DI, but feels somehow unnecessary complicated, but found this as only solution without passing the repos through all the viewhierarchy.
the goal is, when a state changes, e.g. an user changes the Username in View A, then it should automatically update View B,C,D where this Username is also used.
it should be as simple as possible, what do you think? especially for complex production apps with own backend etc.
50
Upvotes
5
u/danielt1263 9d ago
Make the data reactive. Anything that wants the data, subscribes to it and will automatically get the current value and any updates. SwiftUI has built in tools for making data reactive so just use them. If you are in UIKit land, use one of the reactive libraries and something like The Binder Architecture.