You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess my question is why this is called ViewModel instead of (UI?)ObservedObject 🙂
UIObservedObject could work I guess (and would sidestep the “what’s the difference between a model and a view model” question), but I plan to add AppKit support and it didn’t make sense to tie the naming to UIKit
I'm by no means an expert in MVVM, but to me a View Model is a wrapper around a model extracting just the required parts being displayed. And usually (maybe not necessarily) read-only i.e. a struct/value type.
So I was kinda expecting some machinery which can map a model (the observable object) to a viewmodel (the view representation of it).
If you are not going to mix w/ SwiftUI, just @ObservedObject seems decent to me
There is really nothing MVVC specific to it, right?
For MVVC my feeling is that the model should be the observable object, the VM a map of that to a struct on changes, which somehow gets propagated to the VC
I'd call it ObservedObject, because this is what it does. instead of calling body, the UI/AppKit version calls that updateView, which is perfectly in line IMO
That’s a reasonable argument. It’s not in the documentation but this is also a good pattern for migrating code towards SwiftUI, because these objects are already SwiftUI-compatible
So I think that might have been why I was avoiding that name, because it felt “taken” by SwiftUI
It's probably a StateObject in SwiftUI 2 terms 🙂
The text was updated successfully, but these errors were encountered:
As discussed in Slack:
I guess my question is why this is called ViewModel instead of (UI?)ObservedObject 🙂
I'm by no means an expert in MVVM, but to me a View Model is a wrapper around a model extracting just the required parts being displayed. And usually (maybe not necessarily) read-only i.e. a struct/value type.
So I was kinda expecting some machinery which can map a model (the observable object) to a viewmodel (the view representation of it).
If you are not going to mix w/ SwiftUI, just @ObservedObject seems decent to me
There is really nothing MVVC specific to it, right?
For MVVC my feeling is that the model should be the observable object, the VM a map of that to a struct on changes, which somehow gets propagated to the VC
I'd call it ObservedObject, because this is what it does. instead of calling body, the UI/AppKit version calls that updateView, which is perfectly in line IMO
It's probably a StateObject in SwiftUI 2 terms 🙂
The text was updated successfully, but these errors were encountered: