Discussion about this post

User's avatar
Anton Gubarenko's avatar

This is a nice question. It was born IMHO the more and more people started to use SwiftUI in production and environment which is required testing. We have some architectural paradigms from our experience: MVC is bad, layers slicing is good. It was born from non-readable and hardly extendable view merged with logic. View driven paradigm took the declaration of UI and State-machine architecture from different layers and merge it in a rendering engine so it easier to write an app. Entry level were set to match the wider audience. Same as initial Swift idea was to move from Objective-C.

Often when logic becomes complicated and @State vars are hitting a huge amount in file it's almost asking to move to ViewModel for me. Replacing 20 @States in example to 1 Observable leads to cleaner code in my case. Not presuming that it's for everyone of course. But it's not that easy to move all. In example, working on a project with SwiftData. We have modelContext in Environment and want to make requests, add, create in ViewModel. Now we need to pass it somehow and use sort of a DI. So this part of SwiftUI requires an effort to be dealing with. Apple might push us to View-State if they have such plan. But regarding that some videos from WWDC have ViewModels and some not is that among the departments there are no shared codebase. Each team resides on decision made by leads and not all of them are working with SwiftUI. Yes, SwiftUI videos are sure run by the ones who work with it. But approaches for specific features may vary.

Sorry for the long comment)

Expand full comment
1 more comment...

No posts