SE-0289 (review #2): Result Builders

Hello,

Am I the only one to find the placement of @ViewBuilder odd when one declares a function argument?

//                        ~~~~~~~~~~~~
func footer<Footer: View>(@ViewBuilder _ footer: () -> Footer) -> some View { ... }

I always tend to qualify the type of the function itself, because I expect the type to trigger the behavior. And this is also where @escaping attribute goes:

func footer<Footer: View>(_ footer: @ViewBuilder () -> Footer) -> some View { ... }

Compiler complains, but without giving any help. It Are we missing a SwiftUI import? Or maybe it's spelled @viewBuilder? What is wrong?

error: unknown attribute 'ViewBuilder'
func footer<Footer: View>(_ footer: @ViewBuilder () -> Footer) -> some View {
                                     ^

Fortunately, I know how young this feature is, so I don't quite trust the error messages, and am somewhat able to double guess the language. Let's tweak the code until the compiler is happy. Oops, still wrong, and still no clue:

error: expected ':' following argument label and parameter name
func footer<Footer: View>(_ @ViewBuilder footer: () -> Footer) -> some View {
                            ^

Eventually, the "correct" form is more or less the only remaining solution.

I don't wish this adventure to anybody. It's mine every single time I want to use the feature.

I do not understand why builders do not define a regular attribute, placed at their well-known location, the one that is engraved in our muscle memory. Why didn't we follow the route of property wrappers?

Is it still possible to discuss this subject?

7 Likes