Problem
Using a component in SwiftUI views requires the definition of the component standard even when a component is not constraining the Standard
and when the generic constraint is not used in the view:
struct HealthKitPermissions: View {
@EnvironmentObject var healthKitDataSource: HealthKit<FHIR>
// ...
}
In addition, defining a new component requires the definition of a component standard even though the component might not have any constraints on the Standard
(e.g., the storage modules: https://github.com/StanfordSpezi/SpeziStorage)
Solution
It would be great if the injection of the components could happen without generic constraints like:
struct HealthKitPermissions: View {
@EnvironmentObject var healthKitDataSource: HealthKit
// ...
}
In addition, the creation of a component does not require a generic type or fixed-defined type alias. The requirements should rather be moved to the Standard
and not to the Component
.
Additional context
An alternative would be creating a type alias on a global level of a Spezi-based application within the View
scope, e.g.:
extension View {
typealias HealthKitComponent = HealthKit<FHIR>
}
which allows the usage in a view using
struct HealthKitPermissions: View {
@EnvironmentObject var healthKitDataSource: HealthKitComponent
// ...
}
Unfortunately, this is a very application-specific solution and hides the complexity while not accessing the usage of components outside of a view or when passing them between components.
Code of Conduct