79430929

Date: 2025-02-11 18:02:09
Score: 2
Natty:
Report link

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?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Tyler