Since iOS 6, unwind segues have been available to navigate up the scene hierarchy. I am trying to decide on the cleaner/better/preferred/more maintainable method for passing data to a parent view controller. There are some questions that address this from the technical perspective (e.g. "if I have an unwind do I still need a delegate") but I can't find much that addresses the questions of pros/cons.
Option 1: use a delegate.
- Done by passing in the parent view controller as a delegate adhering to a protocol.
- Child calls the protocol method to return the data.
- If data validation is required by the Parent, return value/dict required to allow child to handle error.
- Overhead: Protocol definition and one method in the parent (for data validation and receipt).
Option 2: use an unwind segue
- Done by calling the unwind segue from the child.
- Child adds a segue on its scene by dragging a button or the storyboard itself to
Exit
and naming the segue so it can be withperformSegueWithIdentifier:sender
- Parent implements
returnFromSegueName
(user named method linked to that segue) to grab the data from the child. - Data validation though can only be implemented by also implementing
canPerformUnwindSegueAction:fromViewController:withSender
- Data validation failure will require another property on the Child as this method only accepts a BOOL for return value.
- Child adds a segue on its scene by dragging a button or the storyboard itself to
- Overhead: Two methods, an extra property, plus Storyboard shenanigans.
Overall, delegates are feeling like the cleaner way to go, but perhaps also antiquated. Am I wrong to be leaning in that direction?