NavigationStack is a container view that manages a stack of views for navigation. It lets users move forward and backward through screens, like pages in a book.
Click to reveal answer
beginner
How do you push a new view onto the NavigationStack?
You use NavigationLink inside the NavigationStack. When tapped, it pushes the destination view onto the stack.
Click to reveal answer
intermediate
What is the difference between NavigationStack and NavigationView?
NavigationStack is the modern replacement for NavigationView in iOS 16+. It provides better control and supports programmatic navigation.
Click to reveal answer
intermediate
How can you programmatically control navigation in NavigationStack?
You bind a state variable to the NavigationStack's path. Changing this path variable pushes or pops views programmatically.
Click to reveal answer
beginner
Why is NavigationStack important for accessibility?
NavigationStack maintains a clear navigation hierarchy, helping screen readers understand the app flow. It also supports standard back gestures.
Click to reveal answer
Which SwiftUI view is used to create a navigation stack?
AList
BNavigationView
CTabView
DNavigationStack
✗ Incorrect
NavigationStack is the correct view for managing a stack of navigable views in SwiftUI.
How do you add a new screen to the navigation stack?
AUse VStack
BUse TabView
CUse NavigationLink with a destination view
DUse Button only
✗ Incorrect
NavigationLink pushes a new view onto the NavigationStack when tapped.
What iOS version introduced NavigationStack as a replacement for NavigationView?
AiOS 16
BiOS 15
CiOS 13
DiOS 14
✗ Incorrect
NavigationStack was introduced in iOS 16 to improve navigation handling.
Which property do you bind to control navigation programmatically in NavigationStack?
AisActive
Bpath
Cselection
Dtag
✗ Incorrect
The path property holds the stack of views and can be changed to navigate programmatically.
What gesture does NavigationStack support for going back?
ASwipe from left edge
BDouble tap
CPinch
DLong press
✗ Incorrect
NavigationStack supports the standard swipe from the left edge to go back.
Explain how NavigationStack manages navigation in a SwiftUI app.
Think about how pages in a book work and how you move forward or backward.
You got /4 concepts.
Describe how you can navigate programmatically using NavigationStack.
Consider changing a list of screens to control navigation.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of NavigationStack in SwiftUI?
easy
A. To organize screens in a stack for easy navigation
B. To create animations for buttons
C. To manage data storage locally
D. To handle network requests
Solution
Step 1: Understand NavigationStack role
NavigationStack is designed to manage a stack of views for navigation.
Step 2: Compare with other options
Options A, B, and C relate to networking, animations, and data storage, which are unrelated to navigation stacks.
Final Answer:
To organize screens in a stack for easy navigation -> Option A
Quick Check:
NavigationStack = Screen stack for navigation [OK]
Hint: NavigationStack stacks screens for navigation [OK]
Common Mistakes:
Confusing NavigationStack with animation or data management
Thinking NavigationStack handles network calls
Assuming NavigationStack is for UI styling only
2. Which of the following is the correct syntax to create a navigation link inside a NavigationStack in SwiftUI?
easy
A. NavigationLink(destination: DetailView()) { Text("Go") }
B. NavigationLink { Text("Go") } destination: DetailView()
C. NavigationLink(Text("Go"), DetailView())
D. NavigationLink(destination: "DetailView") { Text("Go") }
Solution
Step 1: Recall NavigationLink syntax
The correct syntax uses NavigationLink(destination: View) { Label }.
Step 2: Check each option
NavigationLink(destination: DetailView()) { Text("Go") } matches the correct syntax. NavigationLink { Text("Go") } destination: DetailView() reverses parameters incorrectly. NavigationLink(Text("Go"), DetailView()) uses wrong parameter order. NavigationLink(destination: "DetailView") { Text("Go") } passes destination as a string, which is invalid.
Final Answer:
NavigationLink(destination: DetailView()) { Text("Go") } -> Option A
Quick Check:
NavigationLink syntax = destination first, label second [OK]
Hint: Destination view goes first, label closure second [OK]
Common Mistakes:
Swapping destination and label parameters
Passing destination as a string instead of a view
Using incorrect parentheses or braces
3. Given this SwiftUI code inside a NavigationStack:
A. Nothing happens because NavigationLink is missing a tag
B. The app navigates to a screen showing "Detail Screen" text
C. The app crashes due to missing navigation title
D. The button changes color but does not navigate
Solution
Step 1: Understand NavigationLink behavior
Tapping the link navigates to the destination view, here a Text view with "Detail Screen".
Step 2: Verify other options
Nothing happens because NavigationLink is missing a tag is incorrect; tags are optional. The app crashes due to missing navigation title is wrong; navigation title is not required to navigate. The button changes color but does not navigate describes visual feedback only, not navigation.
Final Answer:
The app navigates to a screen showing "Detail Screen" text -> Option B
Quick Check:
NavigationLink tap = navigate to destination [OK]
Hint: Tap NavigationLink to go to its destination view [OK]
Common Mistakes:
Thinking NavigationLink needs a tag to work
Assuming navigation title is mandatory for navigation
Confusing visual feedback with navigation action
4. What is wrong with this SwiftUI code snippet inside a NavigationStack?
A. NavigationLink cannot be used inside NavigationStack
B. Text("Next") should be outside the NavigationLink
C. DetailView is missing parentheses to create an instance
D. The destination must be a string, not a view
Solution
Step 1: Check destination parameter
Destination expects a view instance, so DetailView() is required, not just DetailView.
Step 2: Validate other options
Text("Next") should be outside the NavigationLink is wrong; Text is correctly inside NavigationLink. NavigationLink cannot be used inside NavigationStack is false; NavigationLink is designed for NavigationStack. The destination must be a string, not a view is incorrect; destination must be a view, not a string.
Final Answer:
DetailView is missing parentheses to create an instance -> Option C
Quick Check:
Destination needs view instance with () [OK]
Hint: Destination must be a view instance with parentheses [OK]
Common Mistakes:
Passing view type instead of instance as destination
Placing label outside NavigationLink
Confusing destination type with string
5. You want to create a NavigationStack with a list of items. Tapping an item should navigate to a detail view showing the item's name. Which code snippet correctly implements this behavior?
hard
A. NavigationStack {
List(items, id: \.self) { item in
NavigationLink(destination: item) {
Text(item)
}
}
}
B. NavigationStack {
ForEach(items) { item in
NavigationLink(Text(item), destination: Text(item))
}
}
C. NavigationStack {
List(items) { item in
Button(action: { navigateTo(Text(item)) }) {
Text(item)
}
}
}
D. NavigationStack {
List(items, id: \.self) { item in
NavigationLink(destination: Text(item)) {
Text(item)
}
}
}
Solution
Step 1: Check List and NavigationLink usage
NavigationStack {
List(items, id: \.self) { item in
NavigationLink(destination: Text(item)) {
Text(item)
}
}
} correctly uses List with id, and NavigationLink with destination as a Text view showing the item.
Step 2: Analyze other options
NavigationStack {
ForEach(items) { item in
NavigationLink(Text(item), destination: Text(item))
}
} uses incorrect NavigationLink syntax. NavigationStack {
List(items) { item in
Button(action: { navigateTo(Text(item)) }) {
Text(item)
}
}
} uses Button with undefined navigateTo function, which is invalid. NavigationStack {
List(items, id: \.self) { item in
NavigationLink(destination: item) {
Text(item)
}
}
} passes item (a String) directly as destination, which is invalid; destination must be a view.
Final Answer:
NavigationStack with List and NavigationLink using destination: Text(item) -> Option D
Quick Check:
List + NavigationLink with view destination = correct [OK]
Hint: Use NavigationLink with destination view inside List [OK]
Common Mistakes:
Passing data instead of view as destination
Using Button instead of NavigationLink for navigation
Incorrect NavigationLink parameter order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.