0
0
iOS Swiftmobile~5 mins

Passing data to destination in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the common way to pass data between view controllers in iOS using Swift?
You usually pass data by setting a property on the destination view controller before the transition happens, often inside the prepare(for:sender:) method.
Click to reveal answer
beginner
What method do you override to prepare data before a segue transition?
Override the prepare(for segue: UIStoryboardSegue, sender: Any?) method to access the destination view controller and pass data to it.
Click to reveal answer
intermediate
How do you safely get the destination view controller inside prepare(for:sender:)?
Use optional binding (if let) to cast segue.destination to the expected view controller type before setting its properties.
Click to reveal answer
intermediate
Why is it important to pass data before the segue transition completes?
Because the destination view controller's view loads after the segue, so setting data beforehand ensures it is ready when the new screen appears.
Click to reveal answer
advanced
Can you pass data back from the destination to the source view controller using prepare(for:sender:)?
No, prepare(for:sender:) is only for passing data forward. To pass data back, use delegation, closures, or unwind segues.
Click to reveal answer
Which method is used to pass data to the next view controller during a segue?
Aprepare(for:sender:)
BviewDidLoad()
CapplicationDidBecomeActive()
DdidReceiveMemoryWarning()
How do you access the destination view controller inside prepare(for:sender:)?
Asegue.source
Bsegue.destination
Cself.navigationController
Dself.presentedViewController
What Swift feature helps safely cast the destination view controller to the correct type?
AImplicitly unwrapped optionals
BForced unwrapping (!)
COptional binding (if let)
DType inference
When should you pass data to the destination view controller?
AInside viewDidDisappear() of source
BInside viewDidAppear() of destination
CAfter the segue completes
DInside prepare(for:sender:) before segue
Which method is NOT used to pass data back from a destination view controller?
Aprepare(for:sender:)
BDelegation
CUnwind segues
DClosures
Explain how to pass data from one view controller to another using a segue in Swift.
Think about the method called before the screen changes.
You got /3 concepts.
    Describe ways to send data back from a destination view controller to the source view controller.
    Passing data back is different from passing data forward.
    You got /4 concepts.