How can I access a SwiftUI EnvironmentObject w/o property Wrapper

Given a View, how can I access an environment object w/o needing the @Environment() property wrapper.

For example, I can set a value

Code Block swift
myView.environment(\.coordinator, Coordinator())

But I can't
Code Block swift
let coordinator = myView.environment(\.coordinator)
coordinator.someMethod(arg: value)


What am I missing?

Replies

If you want your object to be available to subviews, then you need attach it using the .environmentObject(someObject); Then, in the view you use @EnvironmentObject var myObj: SomeObject