First at all, you missing the left brackets(
in your default value of property rowContent
. Secondly, You can't add @ViewBuilder
to your stored property, @ViewBuilder
is a @resultBuilder
, check this: Result builders in Swift explained with code examples
I tried to achieve your goal, and here is my codeļ¼
struct MenuList<T: MenuListItem, RowContent: View>: View
{
var body: some View { ... }
private let rowContent: (T) -> RowContent
init(@ViewBuilder rowContent: @escaping (T) -> RowContent = { (_: T) in EmptyView() })
{
self.rowContent = rowContent
}
}
But it could be wrong since there not enough details about your code and what you actually want to do. Like what is MenuListItem
and do you expect the generic T
always the same type in one single MenuList
? And why you want to save the closure to your property?