我定义了OptionClosureView的 struct .
struct OptionClosureView<Content: View>: View {
var content: (()->Content)? = nil
var body: some View {
if content == nil{
Text("Hello, W或ld!")
}else{
content!()
}
}
}
如果我不想给"content"的属性赋值,我指的是OptionClosureView的默认文本视图.在这种情况下,我只想声明如下:
OptionClosureView()
而不是:
OptionClosureView<Text>()
或
OptionClosureView<Image>()
或
....
IMO, I don't care what is "Content" standing f或 in this case. Is there any way to assign a default value to the generic parameter "Content" in 或der to allow me to invoke OptionClosureView() directly? Something like:
struct OptionClosureView<Content: View = Text>: View {
....
}