Challenge - 5 Problems
NavigationLink Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when this NavigationLink is tapped?
Consider this SwiftUI code snippet. What will the user see after tapping the NavigationLink?
iOS Swift
NavigationLink(destination: Text("Detail View")) { Text("Go to Detail") }
Attempts:
2 left
💡 Hint
NavigationLink requires a NavigationView ancestor to navigate properly.
✗ Incorrect
Without a NavigationView, NavigationLink renders the label (styled as a link) but does not navigate when tapped.
📝 Syntax
intermediate2:00remaining
Which option correctly creates a NavigationLink with a label and destination?
Choose the correct SwiftUI code that compiles and shows "Next Screen" when tapped.
Attempts:
2 left
💡 Hint
The destination parameter comes first, then the label closure.
✗ Incorrect
Option B uses the correct initializer with destination first and a trailing closure for the label. Others have wrong parameter order or syntax errors.
❓ lifecycle
advanced2:00remaining
What is the effect of using NavigationLink with isActive binding?
Given this code snippet, what happens when isActive becomes true?
iOS Swift
struct ContentView: View {
@State private var isActive = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("Active View"), isActive: $isActive) {
EmptyView()
}
Button("Activate") {
isActive = true
}
}
}
}
}Attempts:
2 left
💡 Hint
The isActive binding controls navigation state programmatically.
✗ Incorrect
When isActive changes to true, the NavigationLink activates and navigates to the destination even without user tapping the label.
🔧 Debug
advanced2:00remaining
Why does this NavigationLink not navigate when tapped?
Identify the reason this NavigationLink does not navigate to the destination view.
iOS Swift
struct ContentView: View {
var body: some View {
VStack {
Text("Hello")
NavigationLink(destination: Text("Next")) {
Text("Go")
}
}
}
}Attempts:
2 left
💡 Hint
NavigationLink requires a NavigationView to manage navigation stack.
✗ Incorrect
Without a NavigationView, NavigationLink cannot push new views onto a navigation stack, so tapping does nothing.
🧠 Conceptual
expert2:00remaining
How does NavigationLink manage navigation stack in SwiftUI?
Which statement best describes how NavigationLink works internally in SwiftUI navigation?
Attempts:
2 left
💡 Hint
Think about how navigation stacks work in iOS apps.
✗ Incorrect
NavigationLink works with NavigationView to push new views onto a stack, allowing back navigation and animation.