this post was submitted on 04 Jun 2025
2 points (100.0% liked)

SwiftUI

172 readers
1 users here now

SwiftUI helps you build great-looking apps across all Apple platforms with the power of Swift — and surprisingly little code.

This is a community for people that use SwiftUI, want to learn SwiftUI or want to show off their creations with SwiftUI.

Want to learn SwiftUI?

Try out Paul Hudson's free 100 Days of SwiftUI course


We expect a civil and constructive discourse in this community.

Piracy:

Bootstrapping:


Other communities on related topics

!hackingwithswift@lemmy.world

!iosprogramming@lemmy.world

!iosprogramming@lemmy.ml

!swift@lemmy.world

!swift@programmers.dev

!swift@lemmy.ml

!swiftui@lemmy.ml

founded 2 years ago
MODERATORS
 

cross-posted from: https://programming.dev/post/31627972

The internet keeps telling me that they go in the model, but some developers tell me that it goes in the view model

Model (Data / Networking / Algorithms) objects represent special knowledge and expertise. They hold an application’s data and define the logic that manipulates that data.
https://developer.apple.com/forums/thread/699003

Therefore, the model can be thought of as representing the app's domain model, which usually includes a data model along with business and validation logic.
https://learn.microsoft.com/en-us/dotnet/architecture/maui/mvvm

Model: Contains the data or the business logic. Any changes in data are communicated to the ViewModel.
https://medium.com/@dilipp817/understanding-mvvm-architecture-a-beginners-guide-to-model-view-viewmodel-8fb05c285710

The Model's purpose is to represent (or model) your business domain. Therefore, business logic by definition goes in the Model, not the ViewModel.https://developer.apple.com/forums/thread/699003
https://stackoverflow.com/questions/37671866/should-i-implement-business-logic-on-a-model-or-a-viewmodel

Even though the vast majority of business logic is present in the data layer, the UI layer can also contain business logic. This can be the case when combining data from multiple repositories to create the screen UI state, or when a particular type of data doesn't require a data layer.\

ViewModel is the right place to handle business logic in the UI layer. The ViewModel is also in charge of handling events and delegating them to other layers of the hierarchy when business logic needs to be applied to modify application data.
https://developer.android.com/topic/libraries/architecture/viewmodel

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here