@ViewBuilder usage explained with code examples

@ViewBuilder usage explained with code examples

The @ViewBuilder attribute is one of the few result builders available for you to use in SwiftUI. You typically use it to create child views for a specific SwiftUI view in a readable way without having to use any return keywords.

[…]

It might surprise you, but you’re likely already using @ViewBuilder in your code. We can take a look at the protocol definition of a SwiftUI View:

[…]

Since we’re using the @ViewBuilder attribute, we can now initialize the view just like a body of a custom SwiftUI View:

[…]