Any2Quiz
Quizzes / Computer Science / Languages / Swift

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, free

Sample questions

  1. 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.

  2. 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.

  3. 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`.

  4. 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.

  5. 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.

Take the full quiz

More questions in this quiz

Answers and explanations are in the full quiz.

  1. Which SwiftUI view modifier is used to apply padding around the content of a view?
  2. What is the purpose of the `@EnvironmentObject` property wrapper in SwiftUI?
  3. How do you create a list in SwiftUI that displays data from an array of identifiable items?
  4. What does the `.frame(maxWidth: .infinity)` modifier achieve in SwiftUI?
  5. Which property wrapper is used to create a two-way binding between a view's state and a piece of data?
  6. What is the primary role of the `.navigationTitle()` modifier in SwiftUI?
  7. When using `GeometryReader`, what does the `proxy.size` property represent?
  8. Which modifier is used to apply an animation to a view's changes in SwiftUI?
  9. What is the function of the `.onAppear()` modifier in SwiftUI?
  10. What is the primary purpose of the `@ObservedObject` property wrapper?
  11. Which SwiftUI view is used to display a scrollable collection of views, optimizing for performance with many items?
  12. What is the role of the `NavigationView` in SwiftUI?
  13. How does the `.sheet()` modifier work in SwiftUI?
  14. What is the default alignment for views within a `VStack` in SwiftUI?
  15. Which property wrapper is used to bind a control's value (like a `TextField` or `Slider`) to a source of truth?
  16. What is the purpose of the `AnyView` type in SwiftUI?
  17. How can you create a user interface element that responds to taps in SwiftUI?
  18. What is the role of the `ObservableObject` protocol in SwiftUI?
  19. In SwiftUI, what is the purpose of the `Identifiable` protocol when used with `List` or `ForEach`?
  20. What does the `ZStack` view do in SwiftUI?
  21. 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?
  22. How do you attach an action to a `Button` in SwiftUI?
  23. What does the `.frame(height: 100)` modifier do to a view?
  24. Which SwiftUI view is used for creating multi-line text input?
  25. What is the function of the `.disabled(_:)` modifier in SwiftUI?
  26. How do you embed a view within another view in SwiftUI to create a custom layout container?
  27. What is the purpose of the `.onDisappear()` modifier in SwiftUI?
  28. What is the primary use case for `@StateObject` compared to `@ObservedObject`?
  29. How can you create a view that contains a title, a text field, and a button in a vertical arrangement?
  30. What is the purpose of the `Binding` property in SwiftUI?
  31. Which SwiftUI modifier is used to change the text color of a `Text` view?
  32. What is the role of `@Published` within an `ObservableObject` class?
  33. How do you dismiss a modal view presented with `.sheet()` in SwiftUI?
  34. What is the default alignment for views within an `HStack` in SwiftUI?
  35. Which of the following is NOT a valid way to define a view's appearance or behavior in SwiftUI?
  36. What does the `.scaledToFit()` modifier do when applied to an `Image` in SwiftUI?
  37. What is the purpose of the `Toggle` view in SwiftUI?
  38. Which property wrapper is used to access data from the environment that has been injected by a parent view or the system?
  39. What does the `.clipShape()` modifier do in SwiftUI?
  40. In SwiftUI, how is a `TextField` typically bound to a `@State` variable?
  41. What is the role of the `Gesture` protocol in SwiftUI?
  42. What is the primary purpose of the `Image` view in SwiftUI?
  43. How do you apply a font style to `Text` in SwiftUI?
  44. What does the `.shadow()` modifier do in SwiftUI?
  45. What is the purpose of the `.toolbar()` modifier in SwiftUI?
  46. How does the `.alignment(_:)` parameter of `VStack` or `HStack` work?

More quizzes

Browse all Swift quizzes

More to play

Daily ChallengeA new quiz every day. Keep your streak.HangmanGuess the word, letter by letter.Story QuestLearn through short interactive stories.All quizzesCBSE, ICSE, competitive exams and more.