I'm trying to create a SwiftUI view that may contain another view like this:
struct EmptyPlaceholderView<Header: View>: View {
let header: Header?
let text: LocalizedStringKey
init(header: Header? = nil, text: LocalizedStringKey) {
self.header = header
self.text = text
}
var body: some View {
VStack(spacing: 8) {
if let header = self.header {
header
}
Text(text)
.scaledFont(.title)
.foregroundColor(.gray500)
}
}
}
this block of code compiles without problems, but when i try to call this view like this: EmptyPlaceholderView(text: "No Data") the compiler fires the following error:
Generic parameter 'Header' could not be inferred
how can I solve this issue ?