[ad_1]
I am utilizing a protocol to outline an override to the default View protocol to create some templated views in my app. They may all share the identical CalculationComponent view for the majority of the structure however then will implement completely different buttons / controls which might be handed by means of with a @ViewBuilder which makes use of generics.
The problem I am having is that when defining my protocol physique, the generic sort is throwing an error the place Sort 'any View' can't conform to 'View'. I believe this has on to do with the <Content material: View> half on CalculationComponent
CalculationComponent.swift
struct CalculationComponent<Content material: View>: View {
@Binding var mainCalculation: String
@Binding var secondaryCalculation: String
@ViewBuilder var content material: () -> Content material
var physique: some View {
// Template UI right here
content material()
}
}
CalculationView.swift
protocol CalculationView: View {
var mainCalculation: String { get set }
var secondaryCalculation: String { get set}
var physique: CalculationComponent<View> { get } // Sort 'any View' can't conform to 'View'
}
CalculatorView.swift
struct CalculatorView: CalculationView {
@State inner var mainCalculation: String = ""
@State inner var secondaryCalculation: String = ""
var physique: CalculationComponent {
CalculationComponent(
mainCalculation: $mainCalculation,
secondaryCalculation: $secondaryCalculation
) {
Textual content("Buttons and look at content material right here")
}
}
}
[ad_2]
