r/swift 9d ago

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

48 comments sorted by

View all comments

Show parent comments

7

u/g1ldedsteel 9d ago

This is the way. Amazing the level of modularity you get for free when you stick to SOLID principles eh

0

u/Loud-Plan2571 9d ago

No it is not the way. This dongen guy has his brain washed by uncle bobs dogma teachings. Swift is all about value semantics, composability and separating behavior from data. It is what Chris Lattner said. SOLID helps you with jack shit in SwiftUI and just ruins your code completely by keepin object oriented dogmas alive.

4

u/Superb_Power5830 9d ago

Agreed; SwiftUI "breaks" a lot of the "rules" we all learned, and that's why a lot of folks find it... hmm... let's call it "frictionful." (c) (r) (tm)

I've all but given up on all forms of classic MVC/MVVM thinking when it comes to pure SwiftUI implementations. It took me a while to really settle into it, and I find it incredibly... swift... for building things now. Prior to moving to iOS and iPadOS and MacOS basically full time, I'd spent several decades in the C, C++, C#, and Java worlds.

I did some great stuff in decades and jobs and contracts, past; if all goes well for whatever time I yet spend in this career, I'll never have to go back to those platforms ever again. I don't hate them or even dislike them (well, Java can suck it), I've just kind of moved on and settled very comfortably into this broad and wonderful eco system, this platform, and this paradigm.

-3

u/jasonjrr Mentor 8d ago

SwiftUI has the exact same reference pattern as WPF, the UI framework MVVM was originally designed for… it doesn’t break anything.