SwiftUI Quiz - Languages Swift
Free practice quiz: SwiftUI (Languages Swift). 51 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This Languages Swift practice quiz has 51 multiple-choice questions on SwiftUI, and 51 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 51 questions, freeSample questions
In SwiftUI, what is the primary purpose of the `@State` property wrapper?
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?
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?
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?
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?
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.
More questions in this quiz
Answers and explanations are in the full quiz.
- Which SwiftUI view modifier is used to apply padding around the content of a view?
- What is the purpose of the `@EnvironmentObject` property wrapper in SwiftUI?
- How do you create a list in SwiftUI that displays data from an array of identifiable items?
- What does the `.frame(maxWidth: .infinity)` modifier achieve in SwiftUI?
- Which property wrapper is used to create a two-way binding between a view's state and a piece of data?
- What is the primary role of the `.navigationTitle()` modifier in SwiftUI?
- When using `GeometryReader`, what does the `proxy.size` property represent?
- Which modifier is used to apply an animation to a view's changes in SwiftUI?
- What is the function of the `.onAppear()` modifier in SwiftUI?
- What is the primary purpose of the `@ObservedObject` property wrapper?
- Which SwiftUI view is used to display a scrollable collection of views, optimizing for performance with many items?
- What is the role of the `NavigationView` in SwiftUI?
- How does the `.sheet()` modifier work in SwiftUI?
- What is the default alignment for views within a `VStack` in SwiftUI?
- Which property wrapper is used to bind a control's value (like a `TextField` or `Slider`) to a source of truth?
- What is the purpose of the `AnyView` type in SwiftUI?
- How can you create a user interface element that responds to taps in SwiftUI?
- What is the role of the `ObservableObject` protocol in SwiftUI?
- In SwiftUI, what is the purpose of the `Identifiable` protocol when used with `List` or `ForEach`?
- What does the `ZStack` view do in SwiftUI?
- Which property wrapper is used to store a value that is owned by the view itself and will cause the view to be re-rendered when it changes?
- How do you attach an action to a `Button` in SwiftUI?
- What does the `.frame(height: 100)` modifier do to a view?
- Which SwiftUI view is used for creating multi-line text input?
- What is the function of the `.disabled(_:)` modifier in SwiftUI?
- How do you embed a view within another view in SwiftUI to create a custom layout container?
- What is the purpose of the `.onDisappear()` modifier in SwiftUI?
- What is the primary use case for `@StateObject` compared to `@ObservedObject`?
- How can you create a view that contains a title, a text field, and a button in a vertical arrangement?
- What is the purpose of the `Binding` property in SwiftUI?
- Which SwiftUI modifier is used to change the text color of a `Text` view?
- What is the role of `@Published` within an `ObservableObject` class?
- How do you dismiss a modal view presented with `.sheet()` in SwiftUI?
- What is the default alignment for views within an `HStack` in SwiftUI?
- Which of the following is NOT a valid way to define a view's appearance or behavior in SwiftUI?
- What does the `.scaledToFit()` modifier do when applied to an `Image` in SwiftUI?
- What is the purpose of the `Toggle` view in SwiftUI?
- Which property wrapper is used to access data from the environment that has been injected by a parent view or the system?
- What does the `.clipShape()` modifier do in SwiftUI?
- In SwiftUI, how is a `TextField` typically bound to a `@State` variable?
- What is the role of the `Gesture` protocol in SwiftUI?
- What is the primary purpose of the `Image` view in SwiftUI?
- How do you apply a font style to `Text` in SwiftUI?
- What does the `.shadow()` modifier do in SwiftUI?
- What is the purpose of the `.toolbar()` modifier in SwiftUI?
- How does the `.alignment(_:)` parameter of `VStack` or `HStack` work?