0
0
iOS Swiftmobile~10 mins

Why navigation structures app flow in iOS Swift - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A.navigationStack()
B.navigationLink()
C.navigationBarTitle("Home")
D.navigationController()
Attempts:
3 left
💡 Hint
Common Mistakes
Using .navigationLink instead of .navigationBarTitle
Trying to call .navigationController() which is UIKit, not SwiftUI
2fill in blank
medium

Complete 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'
A.navigationBarBackButtonHidden(false)
B.isDetailLink(true)
C.navigationTitle("Main")
D.navigationBarHidden(false)
Attempts:
3 left
💡 Hint
Common Mistakes
Using .navigationTitle instead of .isDetailLink
Hiding the back button accidentally
3fill in blank
hard

Fix 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'
Acontroller()
Bcontroller
CController
DController?
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the question mark causes a compile error.
Using wrong capitalization for navigationController.
4fill in blank
hard

Fill 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'
ADetailView()
BText("Show Details")
CButton("Show")
DImage(systemName: "arrow.right")
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.
5fill in blank
hard

Fill 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'
Aid
Bitem.name
CselectedItem
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in navigationDestination closure.
Forgetting to escape id with backslash in List.