SwiftUI Navigation Questions with Answers

12 practice questions on SwiftUI Navigation (iOS (Swift & SwiftUI)) with answers and step-by-step solutions. Try 10 samples below, then practise all 12 free in the AptiNest app.

Sample questions

Question 1Easy

Which view gives an app a bottom tab bar to switch between sections?

  1. NavigationStack
  2. List
  3. Form
  4. TabView

Answer: D. TabView

Explanation

TabView shows one child at a time and a tab bar, configured with .tabItem or Tab.

Step-by-step solution

  1. TabView shows a bottom tab bar with one tab for each of its child views.
  2. NavigationStack handles push and pop screens, not a tab bar.
  3. Marked answer: option D.

Why the other options are wrong

  • A. NavigationStack handles drill-down navigation, not a bottom tab bar.
  • B. List shows rows of content and does not switch sections.
  • C. Form groups input controls for settings-style screens; it is not a tab bar.

Tip: TabView gives bottom tabs; NavigationStack gives push and pop screens.

Question 2Easy

Which SwiftUI view manages a push-style stack of screens?

  1. TabView
  2. ScrollViewReader
  3. NavigationStack
  4. ScrollView

Answer: C. NavigationStack

Explanation

NavigationStack hosts a root view and pushes destination views on top, usually triggered by NavigationLink.

Step-by-step solution

  1. A push-style stack of screens is a navigation stack.
  2. NavigationStack hosts a root view and pushes destinations.

Why the other options are wrong

  • A. TabView switches between tabs.
  • B. ScrollViewReader scrolls to positions.
  • D. ScrollView just scrolls content.

Tip: Stack = push/pop.

Question 3Easy

Which modifier shows a system dialog with a title, message and buttons such as OK and Cancel?

  1. .navigationDestination
  2. .listStyle
  3. .tabItem
  4. .alert

Answer: D. .alert

Explanation

.alert presents a standard alert when its binding becomes true. .confirmationDialog is the action-sheet style alternative.

Step-by-step solution

  1. .alert is used to show system dialogs with title, message, and buttons like OK and Cancel.
  2. Other options do not present dialog boxes with interactive buttons.
  3. The correct modifier for such a dialog is .alert.
  4. Therefore, the answer is .alert.

Why the other options are wrong

  • A. navigationDestination sets up a route for pushing views, not dialogs.
  • B. listStyle only changes list appearance; it does not show a dialog.
  • C. tabItem sets a tab's label and icon, not a dialog.

Tip: Use .alert for showing system dialogs with OK/Cancel buttons in SwiftUI.

Question 4Easy

Which modifier presents a view modally as a card that slides up?

  1. .navigationTitle(_:)
  2. .sheet(isPresented:)
  3. .toolbar(content:)
  4. .refreshable(action:)

Answer: B. .sheet(isPresented:)

Explanation

sheet presents content modally over the current view, driven by a Bool binding or an optional item.

Step-by-step solution

  1. Sheet modifier shows content on top of current view.
  2. .sheet(isPresented:) uses a Bool to control visibility.
  3. It slides up from the bottom like a card animation.
  4. This matches the modal card slide up behavior.
  5. Correct answer is .sheet(isPresented:).

Why the other options are wrong

  • A. navigationTitle sets the title text, not a presentation style.
  • C. toolbar adds toolbar items to a screen; it does not present a view.
  • D. refreshable adds pull-to-refresh to a scroll view; it does not present anything.

Tip: Use .sheet(isPresented:) for modal views that slide up like cards.

Question 5Medium

A NavigationStack is bound to @State var path: [Route]. How do you pop back to the root view?

  1. Replace the stack with a new NavigationStack
  2. Append the root view to the path
  3. Call path.reverse()
  4. Set path to an empty array

Answer: D. Set path to an empty array

Explanation

The path is the stack's state. Removing all elements leaves only the root; removeLast() pops one screen and append pushes one.

Step-by-step solution

  1. Set path to an empty array removes all views from the stack.
  2. This leaves only the root view as the new top of the stack.
  3. Emptying the path effectively pops back to the root view.
  4. The correct action is to set path to an empty array.
  5. Final answer: Set path to an empty array.

Why the other options are wrong

  • A. Creating a new NavigationStack rebuilds the view; clearing the path is the clean pop.
  • B. Appending the root view pushes another screen; it does not pop back.
  • C. reverse() reorders the path array and does not pop the stack.

Tip: To reset NavigationStack, clear the path array.

Question 6Medium

How does a view presented as a sheet close itself?

  1. Return EmptyView() from its body
  2. Call NavigationStack.pop() from inside its parent
  3. Set its own @State isPresented to false
  4. Read @Environment(\.dismiss) and call dismiss()

Answer: D. Read @Environment(\.dismiss) and call dismiss()

Explanation

The dismiss environment action closes the current presentation (sheet or pushed view). The presenter's binding is then updated automatically.

Step-by-step solution

  1. A sheet closes itself through the dismiss action that SwiftUI puts in the environment.
  2. Reading the dismiss value from the environment and calling it closes the sheet it belongs to.
  3. Marked answer: option D.

Why the other options are wrong

  • A. Returning EmptyView() only changes what the body shows; it does not close the sheet.
  • B. A sheet is not a NavigationStack screen, so pop() is not how it closes.
  • C. The flag that shows the sheet is held by the parent, so the sheet's own @State does not close it.

Tip: Inside a presented view, call dismiss() from the environment to close it.

Question 7Medium

How does .fullScreenCover differ from .sheet on iPhone?

  1. It presents the view only on iPad, not iPhone
  2. It fills the screen and can't be swiped down to dismiss
  3. It pushes the view onto the navigation stack instead of presenting
  4. It shows the content as a small popover arrow

Answer: B. It fills the screen and can't be swiped down to dismiss

Explanation

A sheet is a card the user can usually swipe away. A full-screen cover takes the whole screen, so the content must provide its own way to dismiss.

Step-by-step solution

  1. A sheet can be swiped away.
  2. fullScreenCover takes the whole screen.
  3. It has no swipe-to-dismiss.

Why the other options are wrong

  • A. It works on iPhone.
  • C. It presents, not pushes.
  • D. A popover is a different style.

Tip: Provide a close button.

Question 8Medium

Where should .navigationTitle("Inbox") be applied?

  1. On the NavigationStack itself, outside all of its content
  2. To the NavigationLink that leads to the screen
  3. To the App struct's WindowGroup
  4. On a view inside the stack, such as its root content

Answer: D. On a view inside the stack, such as its root content

Explanation

Navigation modifiers are read from the content shown in the stack, so each screen sets its own title on its content.

Step-by-step solution

  1. NavigationStack shows views inside it.
  2. Titles are set on the view inside the stack.
  3. .navigationTitle("Inbox") applies to the view inside the stack.
  4. So, apply it on a view inside the stack, such as its root content.

Why the other options are wrong

  • A. The title belongs to a view inside the stack, not to the wrapper itself.
  • B. A NavigationLink is the link itself; the title belongs on the destination view.
  • C. WindowGroup is the scene, not a screen in the stack, so the title does not go there.

Tip: Set .navigationTitle() on the view inside the NavigationStack, not outside.

Question 9Hard

What must values used with NavigationLink(value:) and navigationDestination(for:) conform to?

  1. Codable
  2. Hashable
  3. Identifiable
  4. Comparable

Answer: B. Hashable

Explanation

Navigation values are stored in the path and compared, so they must be Hashable. Codable is only needed to save and restore a NavigationPath.

Step-by-step solution

  1. NavigationLink(value:) uses a value to identify destinations.
  2. navigationDestination(for:) compares values in the navigation path.
  3. Comparing values requires them to be Hashable.
  4. Hashable conforms to the required protocol for comparison.
  5. Final answer: B (Hashable).

Why the other options are wrong

  • A. Codable is for encoding and decoding; navigation matching uses Hashable.
  • C. Identifiable gives ForEach identity; navigation values need Hashable.
  • D. Comparable is for ordering; navigation needs equality and hashing, which Hashable gives.

Tip: Remember: Hashable is needed for navigation value comparison.

Question 10Hard

When is NavigationSplitView a better fit than NavigationStack?

  1. Multi-column layouts, like a sidebar plus detail on iPad
  2. Apps that do not need any navigation at all
  3. Simple single-column screens on iPhone with no sidebar at all
  4. Showing modal sheets that cover the screen

Answer: A. Multi-column layouts, like a sidebar plus detail on iPad

Explanation

NavigationSplitView shows two or three columns on large screens and collapses into a stack on compact widths such as iPhone.

Step-by-step solution

  1. NavigationSplitView supports multi-column layouts like sidebar plus detail on iPad.
  2. It adapts to different screen sizes by collapsing into a stack on smaller devices.
  3. NavigationStack is for single-column navigation without sidebars.
  4. Modal sheets that cover the screen are shown with .sheet or .fullScreenCover, not by either stack or split view.
  5. So, NavigationSplitView is better for multi-column layouts on iPad.

Why the other options are wrong

  • B. Even simple apps use a stack or split view for navigation; this is not the reason to pick it.
  • C. A single-column screen suits NavigationStack, so split view is not the better fit.
  • D. Sheets come from .sheet or .fullScreenCover, not from a split view.

Tip: Use NavigationSplitView for complex layouts on larger devices; NavigationStack for simplicity.

Practise all 12 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all iOS (Swift & SwiftUI) topics · All topics