Bird
0
0

Which of the following is the correct syntax to create a NavigationLink with a text label "Next" that opens DetailView()?

easy📝 Syntax Q12 of 15
iOS Swift - Navigation
Which of the following is the correct syntax to create a NavigationLink with a text label "Next" that opens DetailView()?
ANavigationLink(destination: Text("Next")) { DetailView() }
BNavigationLink(destination: Text("Next"), DetailView())
CNavigationLink { DetailView() } label: { Text("Next") }
DNavigationLink(destination: DetailView()) { Text("Next") }
Step-by-Step Solution
Solution:
  1. Step 1: Recall NavigationLink syntax

    The correct syntax uses NavigationLink(destination: View) { LabelView }.
  2. Step 2: Check each option

    NavigationLink(destination: DetailView()) { Text("Next") } matches the correct syntax. NavigationLink(destination: Text("Next"), DetailView()) swaps parameters incorrectly. NavigationLink { DetailView() } label: { Text("Next") } uses a newer syntax and is valid in SwiftUI 3+, so it is also correct. NavigationLink(destination: Text("Next")) { DetailView() } swaps destination and label views wrongly.
  3. Final Answer:

    NavigationLink(destination: DetailView()) { Text("Next") } -> Option D
  4. Quick Check:

    Correct parameter order = NavigationLink(destination: DetailView()) { Text("Next") } [OK]
Quick Trick: Destination first, label inside closure for NavigationLink [OK]
Common Mistakes:
  • Swapping destination and label parameters
  • Using incorrect closure syntax
  • Passing views in wrong order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes