I have learned how to pass data from ViewController1 to ViewController2. Using the prepareForSegue method. What I do not understand is how to pass data back from ViewController2 to ViewController1. Do I just create another segue going back to ViewController1, along with a whole new prepareForSegue method in ViewController2? Or is there a way to reduce the code and use the original prepare for segue in ViewController1?
Asked
Active
Viewed 57 times
0
-
1The usual ways are protocol/delegate or – more contemporary – a callback closure to be called in `viewWillDisappear`. – vadian Jul 05 '16 at 15:12
-
1No, don't use another segue, you don't want to make new instance of vc1. You may use _delegate pattern_, or you may use your data source (depends on data model). I recommend to read some docs/templates about delegate pattern in iOS **upd** and closures for sure, how did I forgot – Yury Jul 05 '16 at 15:12