SwiftUI Quiz - Languages Swift
Free practice quiz: SwiftUI (Languages Swift). 51 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 51 questions freeSample questions
In SwiftUI, what is the primary purpose of the `@State` property wrapper?
- To manage shared data across multiple views
- To hold immutable data that doesn't change
- To manage local, mutable state within a single view
- To observe changes in external data sources
Show answer
Answer: C. To manage local, mutable state within a single view
`@State` is used to declare a source of truth for data that is local to a specific view and can be modified by that view. When the state changes, SwiftUI automatically re-renders the view.
How can you create a horizontal stack of views in SwiftUI?
- Using `VStack`
- Using `ZStack`
- Using `HStack`
- Using `ForEach`
Show answer
Answer: C. Using `HStack`
`HStack` is a container view that arranges its child views in a horizontal line.
Which modifier is used to define a custom transition when a view appears or disappears?
- .animation()
- .transition()
- .effect()
- .animationCurve()
Show answer
Answer: B. .transition()
The `.transition()` modifier allows you to specify custom animations for when a view is added to or removed from the view hierarchy. Examples include `.slide`, `.opacity`, or `.scale`.
Which of these is NOT a built-in layout container in SwiftUI?
- VStack
- HStack
- Grid
- ZStack
Show answer
Answer: C. Grid
While SwiftUI has introduced `Grid` and `LazyVGrid`/`LazyHGrid` for more complex grid layouts, `VStack`, `HStack`, and `ZStack` are the fundamental linear and overlay layout containers.
How do you present a navigation link in SwiftUI?
- Using the `.present()` modifier
- Using `NavigationLink(destination:label:)`
- Using the `.push()` modifier
- Using the `.sheet()` modifier
Show answer
Answer: B. Using `NavigationLink(destination:label:)`
`NavigationLink` is the primary SwiftUI view for creating navigation destinations. It wraps a label (like a `Text` or `Button`) and a destination view that is pushed onto the `NavigationView` stack when the label is tapped.