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

Swift

421 readers
1 users here now

This group focus on the content related to the development of Apple Eco-system software. So feel free to share and talk about, for example;

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

top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 5 days ago

Business logic should be in a set of ui agnostic classes called from where it is most useful. That probably would be the view model but in general your business logic shouldn't be coupled to your ui.