I’m referring to the injection of a model container into the environment. We accomplish this by declaring the type as follows:
.modelContainer(for: [Book.self, Author.self])
For instance:
struct Example: App {
@State private var appData = ApplicationData.shared
var body: some Scene {
WindowGroup {
ContentView()
.environment(appData)
.modelContainer(for: [Book.self, Author.self])
}
}
}
I was wondering if we could implement a feature similar to the navigationPath() type-erasing functionality. This allows us to define a heterogeneous set of types, as we can do with:
@State private var path = NavigationPath()
Instead of explicitly declaring:
@State private var path = [Book] ()
Is there a way to build ( if not already a way) into Swift Language a similar capability for environment injection, enabling the injection of a heterogeneous set of types without needing to declare the type explicitly?