Recall & Review
beginner
What is a @ViewBuilder in SwiftUI?
A @ViewBuilder is a special attribute that lets you create custom container views by combining multiple child views into one. It helps build complex UI layouts by grouping views together.
Click to reveal answer
beginner
How does @ViewBuilder help when creating custom containers?
It allows you to write multiple views inside a closure without needing to wrap them manually. SwiftUI then combines these views into a single view group automatically.
Click to reveal answer
intermediate
What is the benefit of using a custom container with @ViewBuilder over a simple VStack or HStack?
Custom containers let you create reusable layouts with your own rules and styles, making your UI code cleaner and easier to manage.Click to reveal answer
intermediate
In SwiftUI, what type does a function marked with @ViewBuilder return?
It returns some View, which means it returns a view or a group of views combined into one, but the exact type is hidden.
Click to reveal answer
advanced
Can you use @ViewBuilder with functions that return more than 10 views?
No, @ViewBuilder supports up to 10 views inside the closure. For more views, you need to group them manually or use other containers.
Click to reveal answer
What does the @ViewBuilder attribute do in SwiftUI?
✗ Incorrect
The @ViewBuilder attribute allows you to write multiple views inside a closure and SwiftUI combines them into a single view container.
Which keyword is used to mark a function that builds multiple views in SwiftUI?
✗ Incorrect
@ViewBuilder is the special attribute used to build multiple views inside a closure.
What is the return type of a function using @ViewBuilder?
✗ Incorrect
Functions with @ViewBuilder return some View, meaning a view or group of views.
Why create custom containers with @ViewBuilder instead of just using VStack or HStack?
✗ Incorrect
Custom containers allow you to reuse layout logic and style your UI consistently.
What is a limitation of @ViewBuilder regarding the number of views?
✗ Incorrect
@ViewBuilder supports up to 10 views inside its closure. More views require manual grouping.
Explain how @ViewBuilder helps in creating custom container views in SwiftUI.
Think about how you can group views without extra wrappers.
You got /4 concepts.
Describe a scenario where you would use a custom container with @ViewBuilder instead of VStack or HStack.
Imagine making a special card or panel used many times.
You got /4 concepts.