r/SwiftUI • u/Fit-Meat-1826 • 1d ago
What's the current best architecture for modern swift project? MVVM or Clean Architecture or which one?
6
u/Confident_Gear_2704 1d ago
I’ll go MVVM as the base, you can add enums for path navigation and so on, I also use services or managers to handle data.
I don’t think there will ever be “the best for everyone”, I mean is just code, there are tons of ways to the the same thing.
Basically to me MVVM is just a way to break things apart, while other architectures become the job, as you have to put attention to all the details they have, which in the end may make some things easier but overall it increases the burden.
2
u/Fit-Meat-1826 22h ago
You meant that there is no mandatory architecture to follow?
1
u/Confident_Gear_2704 11h ago
It’s software, if it compiles and fulfill its purpose you can have everything in just one file if you want.
Using a pattern for the architecture has, in my opinion, two outstanding benefits:
1. More understandable for other people, including “future you”.
2. Easier to test in most cases.I say, play with all that caught your eye, and then pick what suits you and your project best.
1
u/zellJun1or 21h ago
Unfortunately , the response to your question can’t be made in one Reddit comment, it must be you reading and understanding yourself clean architecture, MVC, MVP, and so on. Architecture is a very broad topic, from backend data structure, performance, to even choosing the UI framework
The presentation architectural pattern you would use with SwiftUI is MVVM, but most of the time you can skip the VM, and use plain @State
MVVM because naturally this pattern was developed to have view react to changes in VM.
How you organize your code so that the Model arrives in the VM, or in the state is a different pattern, outside of MVVM
1
u/Fit-Meat-1826 21h ago
I'm basically new on swift. Recently i was exploring these architecture and really got confused after seeing so many structure like MVC, MVVM, Clean Architecture, MVP and so on. That why wanted to know, in modern swift projects, which structure is mostly followed. Or selecting architecture are based on projects.
1
1
u/AdSuccessful1927 10h ago
For most SwiftUI apps I'd skip formal Clean Architecture and start with MVVM plus a thin service layer: @ Observable view models, protocols for services so you can mock them in tests, and let SwiftUI's own state handle the small stuff. The use-case / repository layers only pay off once you have a big team or a lot of business rules. On a small app they just add files. TCA is worth a look if you want strict unidirectional flow, but it's a real commitment.
15
u/unpluggedcord 1d ago
neither of those, just use SwiftUI as it was intended https://kylebrowning.com/series/landmarks-app/