Challenge - 5 Problems
Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What happens when this SwiftUI button is tapped?
Consider this SwiftUI code snippet. What is the visible result when the button is tapped?
iOS Swift
struct ContentView: View {
@State private var isDetailActive = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: Text("Detail View"), isActive: $isDetailActive) {
EmptyView()
}
Button("Go to Detail") {
isDetailActive = true
}
}
}
}
}Attempts:
2 left
💡 Hint
Think about how NavigationLink with isActive binding works in SwiftUI.
✗ Incorrect
The NavigationLink is activated programmatically by setting isDetailActive to true, causing navigation to the destination view.
❓ lifecycle
intermediate2:00remaining
What is the effect of calling pushViewController in UIKit?
In UIKit, what happens when you call navigationController?.pushViewController(newVC, animated: true)?
Attempts:
2 left
💡 Hint
Think about how navigation stacks work in UIKit.
✗ Incorrect
pushViewController adds the new view controller to the navigation stack and shows it with animation if requested.
📝 Syntax
advanced2:00remaining
Which Swift code correctly performs programmatic navigation in SwiftUI?
Select the code snippet that correctly navigates to DetailView when a button is pressed.
iOS Swift
struct ContentView: View {
@State private var showDetail = false
var body: some View {
NavigationView {
VStack {
Button("Show Detail") {
showDetail = true
}
// NavigationLink here
}
}
}
}Attempts:
2 left
💡 Hint
Check the correct use of isActive binding in NavigationLink.
✗ Incorrect
Option B correctly binds isActive to $showDetail and uses an EmptyView as label for programmatic navigation.
🔧 Debug
advanced2:00remaining
Why does this UIKit navigation code fail to show the new screen?
Given this code snippet, why does tapping the button not navigate to NewViewController?
class ViewController: UIViewController {
@IBAction func buttonTapped(_ sender: UIButton) {
let newVC = NewViewController()
newVC.modalPresentationStyle = .fullScreen
}
}
Attempts:
2 left
💡 Hint
Check if the new view controller is actually shown.
✗ Incorrect
The code creates newVC but does not call pushViewController or present, so no navigation occurs.
🧠 Conceptual
expert2:00remaining
What is the main difference between programmatic navigation and declarative navigation in iOS?
Choose the best explanation of the difference between programmatic navigation (UIKit) and declarative navigation (SwiftUI).
Attempts:
2 left
💡 Hint
Think about how navigation is triggered in UIKit vs SwiftUI.
✗ Incorrect
UIKit navigation is done by calling methods to push or present views. SwiftUI navigation is controlled by state variables that describe navigation state declaratively.