Bird
0
0

ProfileViewController { dest.userName = "Alice" } What will be the value of userName in ProfileViewController after the segue?

medium📝 Predict Output Q4 of 15
iOS Swift - Navigation
Given the following code in prepare(for:sender:): if let dest = segue.destination as? ProfileViewController { dest.userName = "Alice" } What will be the value of userName in ProfileViewController after the segue?
A"Alice"
Bnil
C"Bob"
DEmpty string ""
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the assignment in prepare(for:sender:)

    The code assigns the string "Alice" to the userName property of the destination controller.
  2. Step 2: Understand that this value is passed before the segue

    Since the assignment happens before the transition, the destination will have userName set to "Alice".
  3. Final Answer:

    "Alice" -> Option A
  4. Quick Check:

    Assigned value = "Alice" [OK]
Quick Trick: Data assigned in prepare(for:) is available after segue [OK]
Common Mistakes:
  • Assuming userName remains nil
  • Confusing with default values
  • Thinking assignment happens after view loads

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes