Lets say I have a View
with Environment Object
like this:
struct MyView: View {
@EnvironmentObject
var viewModel: RegisterViewModel
}
and somewhere in ancestor I would provide this object like this:
NavigationView {
LoginView()
}
.environmentObject(RegisterViewModel())
What is the mechanics of actually assigning this value to var viewModel
. Nowhere in my code I needed to specify the name of variable, and yet it's correctly assigned. What will happened if I have few environment objects of the same type?