Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a navigation controller in SwiftUI.
iOS Swift
NavigationView {
Text("Home Screen")
}.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .navigationLink instead of .navigationBarTitle
Trying to call .navigationController() which is UIKit, not SwiftUI
✗ Incorrect
The .navigationBarTitle modifier sets the title of the navigation bar in a NavigationView.
2fill in blank
mediumComplete the code to navigate to a detail view when a button is tapped.
iOS Swift
NavigationLink(destination: DetailView()) {
Text("Go to Detail")
}.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .navigationTitle instead of .isDetailLink
Hiding the back button accidentally
✗ Incorrect
The .isDetailLink(true) modifier tells SwiftUI this link leads to a detail view in navigation.
3fill in blank
hardFix the error in the code to push a new view onto the navigation stack.
iOS Swift
NavigationView {
VStack {
Button("Next") {
navigation[1].pushViewController(NextViewController(), animated: true)
}
}
}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the question mark causes a compile error.
Using wrong capitalization for navigationController.
✗ Incorrect
navigationController? is optional and must be safely unwrapped to call pushViewController.
4fill in blank
hardFill both blanks to create a navigation link with a label and destination view.
iOS Swift
NavigationLink(destination: [1]) { [2] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Button inside NavigationLink label causes nested buttons error.
Using a view type instead of an instance for destination.
✗ Incorrect
The destination is DetailView() and the label is a Text view showing "Show Details".
5fill in blank
hardFill all three blanks to create a navigation stack with a list and navigation links.
iOS Swift
NavigationStack {
List(items, id: \.[1]) { item in
NavigationLink(value: item) {
Text([2])
}
}
.navigationDestination(for: Item.self) { [3] in
DetailView(item: [3])
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in navigationDestination closure.
Forgetting to escape id with backslash in List.
✗ Incorrect
The list uses id: \.id, label shows item.name, and navigationDestination uses 'item' as parameter.