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

Play all 51 questions free

Sample questions

  1. In SwiftUI, what is the primary purpose of the `@State` property wrapper?

    1. To manage shared data across multiple views
    2. To hold immutable data that doesn't change
    3. To manage local, mutable state within a single view
    4. 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.

  2. How can you create a horizontal stack of views in SwiftUI?

    1. Using `VStack`
    2. Using `ZStack`
    3. Using `HStack`
    4. Using `ForEach`
    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?

    1. .animation()
    2. .transition()
    3. .effect()
    4. .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`.

  4. Which of these is NOT a built-in layout container in SwiftUI?

    1. VStack
    2. HStack
    3. Grid
    4. 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.

  5. How do you present a navigation link in SwiftUI?

    1. Using the `.present()` modifier
    2. Using `NavigationLink(destination:label:)`
    3. Using the `.push()` modifier
    4. 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.

Take the full quiz

More quizzes

Browse all Swift quizzes