0
0
iOS Swiftmobile~20 mins

NavigationLink in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NavigationLink Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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")
}
ANothing happens because the NavigationLink is missing a NavigationView.
BThe app navigates to a new screen showing the text "Detail View".
CThe app crashes due to missing navigation context.
DThe text "Go to Detail" changes color but no navigation occurs.
Attempts:
2 left
💡 Hint
NavigationLink requires a NavigationView ancestor to navigate properly.
📝 Syntax
intermediate
2: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.
ANavigationLink(Text("Tap Here"), destination: Text("Next Screen"))
B
NavigationLink(destination: Text("Next Screen")) {
  Text("Tap Here")
}
CNavigationLink(destination: Text("Next Screen"), label: { Text("Tap Here") })
D
NavigationLink(Text("Next Screen")) {
  Text("Tap Here")
}
Attempts:
2 left
💡 Hint
The destination parameter comes first, then the label closure.
lifecycle
advanced
2: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
        }
      }
    }
  }
}
ATapping the button programmatically navigates to the "Active View" screen.
BNothing happens because the NavigationLink label is EmptyView.
CThe button toggles the visibility of the NavigationLink label.
DThe app crashes due to binding misuse.
Attempts:
2 left
💡 Hint
The isActive binding controls navigation state programmatically.
🔧 Debug
advanced
2: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")
      }
    }
  }
}
AThe destination view is missing a NavigationLink label.
BThe NavigationLink label is not tappable because it's a Text view.
CBecause NavigationLink is not inside a NavigationView, navigation won't work.
DThe code is missing a @State variable to control navigation.
Attempts:
2 left
💡 Hint
NavigationLink requires a NavigationView to manage navigation stack.
🧠 Conceptual
expert
2:00remaining
How does NavigationLink manage navigation stack in SwiftUI?
Which statement best describes how NavigationLink works internally in SwiftUI navigation?
ANavigationLink swaps the current view with the destination view without animation.
BNavigationLink replaces the root view with the destination view immediately on tap.
CNavigationLink creates a modal sheet presenting the destination view over the current view.
DNavigationLink pushes the destination view onto the navigation stack managed by NavigationView when activated.
Attempts:
2 left
💡 Hint
Think about how navigation stacks work in iOS apps.