So I am making an attempt to adapt to a protocol utilizing an @EnvironmentObject variable, however the compiler complains, whereas if a use @ObservedObject it really works.
Utilizing @EnvironmentObject:
ultimate class ViewModel: ObservableObject {
@Revealed var someOutput: String
init(someOutput: String) {
self.someOutput = someOutput
}
}
protocol SomeChildView: View {
var viewModel: ViewModel { get set }
}
struct FirstChildView: SomeChildView {
@EnvironmentObject var viewModel: ViewModel // <-- This doesn't work.
var physique: some View {
Textual content("")
}
}
Utilizing @ObservedObject:
struct FirstChildView: SomeChildView {
@ObservedObject var viewModel: ViewModel // <-- Works
var physique: some View {
Textual content("")
}
}