swift-cross-ui icon indicating copy to clipboard operation
swift-cross-ui copied to clipboard

Support environment insertion of arbitrary ObservableObjects (or other observable types)

Open MiaKoring opened this issue 2 months ago • 0 comments

SwiftUI allows inserting Observable (@Observable) directly into the environment without EnvironmentKeys (ObservableObjects through .environmentObject). You would access them through @Environment(XYZ.self) and @EnvironmentObject(ZYX.self) respectively.

I believe we should add this ourselves, because its very useful for app state for example.

Once the pr allowing environment insertions through EnvironmentKey is merged, I’m going to work on the implementation. I’m not entirely sure why SwiftUI separates @Observable and ObservableObject in this case, both should just be references internally. It might be due to the way they propagate view updates. With SCUIs ObservableObject being compatible with @State I believe we don’t need this separation.

MiaKoring avatar Dec 13 '25 22:12 MiaKoring