Open helje5 opened 4 years ago
This is kind of disappointing — I tried renaming to ObservedObject
, and this is the compiler error when importing both CombineViewModel and SwiftUI:
Sources/App/ProfileViewController.swift:7:3: error: unknown attribute 'ObservedObject'
@ObservedObject var viewModel: ProfileViewModel
^
Qualifying with the module name still works, it just that this diagnostic is not helpful at all.
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 🙂