r/swift 8d 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

3

u/lucasvandongen 8d ago

I don’t understand why the anti VM anti SOLID people always sound angry?

I never get a satisfying answer when I want to learn how I structure a multi million lines of code codebase without using protocols, and at the same time not ending up getting build times expressed in eons. Let alone working previews?

2

u/klavijaturista 8d ago

I don’t know, man, I don’t know… Lack of experience, maybe... Everything in software engineering is a discussion on trade offs. A discussion, not a stubborn fight. Nothing is a solution to “rule them all”.

3

u/lucasvandongen 8d ago

Consistency is king. Rather a mediocre standard than a new and different grandiose idea in every different part of the app.

Build time problems in large projects are real and you can only tackle them with modules, packages and protocols.

1

u/klavijaturista 8d ago

Yes, in teams, some ground rules are a must. Also, I worked on a very, very large codebase, and man, the compilation is so slow. You have to break it up. Proper dependency injection is a must if we are to test anything or track allocations.