The preferred way for this would be to use delegation, e.g. tell S2
to report back to S1
.
Another answer tried to make this point already, yet didn't make clear what is going on.
The idea is to have S2
hold a reference to S1
and report back. It comes in handy that you are not using segues; they would make it minimally more complex.
Protocol
You can do so by creating a protocol for communication:
protocol ReportBackProtocol {
func reportValues(someValues : SomeType)
}
S1
Within S1
, you implement ReportBackProtocol
like so:
class S1 : UIViewController, ReportBackProtocol {
// all your S1 class things
func reportValues(someValues : SomeType) {
// do with the values whatever you like in the scope of S1
}
And assign your S1
instance as a delegate of your S2
instance where you create it, before you present it:
let s2 = S2()
s2.delegate = self
// present it as you already do
S2
In S2
, wherever you have compiled your values (let's call them x
) and are ready to send them back:
self.delegate?.reportValues(x)
You also need to add the delegate instance variable to S2
like so:
weak var delegate : ReportBackProtocol?
This should do the trick; please let me know if you run into problems or do not understand parts of the concept.