I've done some reading on here about passing data back from view controllers and I know that there are some definitely no-no's about this, but I wanted to inquire about a best practice for passing data in this manner and ask if what i'm doing below is ok?
I have 3 view controllers (classes ViewControllerA, B, and C) and when the user clicks a button (from either A, or B) it takes them to C using this:
let vc = new ViewControllerC()
self.presentViewController(vc, animated: true, completion: nil)
Passing data forward So 'self' above is either A, or B. My thought was if I wanted to send C some info, I could just make a property of C (such as a string or int, etc, etc) and assign it above just before I do a presentViewController. Is that right?
i.e. vc.propertyHere = "my value"
Passing Data Back if something happened in C that I'd like to send back to A or B, what is the best practice? To return back to A or B I know I can do this: self.dismissModalViewControllerAnimated(true)
Should I first instantiate A or B (maybe by their base type) and access a similar property for the information I'd like to pass back? For example if A and B both inherit from some class, I could make a property on that class and just access / set it from C. Is that the right move? Or is there a better approach? i.e.
callingViewController.myProperty = "my value i'm passing back"
Thanks!