0% found this document useful (0 votes)
7 views1 page

View Builder

The document explains how SwiftUI builds views using the `ViewBuilder` function, specifically focusing on creating an `EmptyView` when no views are passed and handling a single child view. It provides code examples demonstrating both scenarios, where an empty group results in no visible output and a single text view displays on the screen. The document emphasizes that these functions should not be called directly as they operate automatically behind the scenes.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

View Builder

The document explains how SwiftUI builds views using the `ViewBuilder` function, specifically focusing on creating an `EmptyView` when no views are passed and handling a single child view. It provides code examples demonstrating both scenarios, where an empty group results in no visible output and a single text view displays on the screen. The document emphasizes that these functions should not be called directly as they operate automatically behind the scenes.

Uploaded by

jon.moses2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Builds an empty view from a block containing no statements.

Don't call this function directly


This works behind the scenes whenever you pass no
views to a ``ViewBuilder``. SwiftUI will automatically build
an ``EmptyView`` when you pass no parameters.

For example, in the following piece of code, we get nothing


on screen. It still builds and runs though, since it interprets no
views as an ``EmptyView``.

```
struct ContentView: View {
var body: some View {
Group { }
}
}
```
![A screenshot displaying an empty view.](buildblock-view.png)

Passes a single view written as a child view through unmodified.

Don't call this function directly.


This works behind the scenes whenever you pass one
view to a ``ViewBuilder``. SwiftUI will automatically build
this into a format that can be handled by the initializer.

For example, in the following piece of code, we get just the one
view on screen.

```
struct ContentView: View {
var body: some View {
Group {
Text("I am all alone ")
}
}
}
```

![A screenshot displaying a single text view that reads "I am all alone"
in the center of the screen.](buildblock-1-view.png)

You might also like