Bird
0
0

Which SwiftUI code snippet correctly implements this using NavigationLink inside a List?

hard📝 Application Q9 of 15
iOS Swift - Navigation
You want to display a list of fruits where tapping each fruit navigates to a detail view showing the fruit's name. Which SwiftUI code snippet correctly implements this using NavigationLink inside a List?
A<pre>List(fruits, id: \.self) { fruit in NavigationLink(destination: Text(fruit)) { Text(fruit) } }</pre>
B<pre>List(fruits) { fruit in Text(fruit) NavigationLink(destination: Text(fruit)) }</pre>
C<pre>ForEach(fruits, id: \.self) { fruit in NavigationLink(label: Text(fruit), destination: Text(fruit)) }</pre>
D<pre>List(fruits) { fruit in NavigationLink(destination: Text(fruit)) }</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Use List with identifiable data

    Use List(fruits, id: \.self) to iterate over fruit names.
  2. Step 2: Wrap each item in NavigationLink

    Each row should be a NavigationLink with destination showing the fruit name and label showing the fruit.
  3. Step 3: Verify syntax correctness

    List(fruits, id: \.self) { fruit in
      NavigationLink(destination: Text(fruit)) {
        Text(fruit)
      }
    }
    correctly uses trailing closure syntax for NavigationLink inside List.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    NavigationLink inside List with destination and label [OK]
Quick Trick: Use NavigationLink inside List with destination and label closures [OK]
Common Mistakes:
  • Placing NavigationLink outside List row
  • Missing label closure in NavigationLink
  • Incorrect List or ForEach usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes