I think you did fine work on tutorial. My concern is that MVVM doesn’t work well with SwiftUI, especially for beginners.
I’ll clarify some of the points you mentioned.
First, sorry for confusion. I meant to say
class WeeklyWeatherViewModel: ObservableObject is a reference type view model, whereas
struct WeeklyWeatherView: View is value type.
The fundamental difference of opinion is that is
struct WeeklyWeatherView: View a view or a model?
You think it’s a view because it conforms to View. I think it’s a model that can be used to construct a view.
I’d argue that a view like Button needs to be reference type because it has mutable properties like title, color, …etc. So the fact that
WeeklyWeatherView is a value type makes it a model. A naming of
struct WeeklyWeather: View would make this model-view map relation more clear.
For nesting views, I think there’s a difference between
nesting views and
nesting view models. Nesting views are common of course. But your view models are not views. They don’t even conform to View. And the worst of all, they may contain side effects like networking. In old days, UIViewController clearly cannot be used as view model so there’s no risk of nesting view model (at least not immediately).
But SDK changes. From what I can tell, SwiftUI has some of the MVVM features built-in. For argument’s sake let’s assume
struct WeeklyWeather: View is indeed a view model. Now do you create a new view model or just straight up use it?
As for nested view model being “accepted”. I’d say from my experience it often makes the code more complicated, so not accepted by me personally. I’m sure it has some merits, and the point I’m trying to make here it to provide an alternative. Developers should make their own calls.
class WeeklyWeatherViewModel: ObservableObject being a reference type. Yes you can use access control or other means for better safety. But the point I’m making is that it’s dangerous for beginners because they don’t know they need to. Even experienced developers would often abuse reference type.
I think SwiftUI doesn’t care if you have “good intentions”. Immutable type and compiler check are the safest bets, which is why I say view model should be value type and that type is required by SwiftUI by default. These are design patterns accepted by SwiftUI itself.
Lastly, as you said, the tutorial may have to change name if you remove all view models.
I’m not asking you to. A comparison is a good thing. But I do think MVVM may not be as “good” as before SwiftUI, and this needs to be pointed out.
Well, it’s not like a lot of people would read comments anyway
So I think I’ll leave the discussion here. People who read this can make up their own minds.