pass delegate from one VC to another withOut using prepareForSegue

118 views Asked by At

So i know how to make delegates and pass them using prepare for segue; however, I have a 3 Views (lets Call them A, B & C). View A connect to view B. View B has a button that leads to view C. In View C, there is a switch that toggles...

view connection: A->B->C

I want to make it so when the switch is toggled in View C, View A knows about it. without using KVO since the relationship is still 1-to-1

2

There are 2 answers

0
Joe Smith On

You can pass a closure A->B->C, invoke the closure in View C when the switch is toggled and pass whatever info you want to the closure to inform View A.

0
dahiya_boy On

In VCA

let vcB = storyboard.instantiateViewControllerWithIdentifier("VCB") as VCB 
vcB.myDataB = "set my data"
navigationController?.pushViewController(vcB,animated: true)

In VCB create property

var myDataB : String!

Now, in VCB push your VC

let vcC = storyboard.instantiateViewControllerWithIdentifier("VCC") as VCC 
    vcC.myDataC = myDataB
    navigationController?.pushViewController(vcC,animated: true)

Now, in VCC, create property,

var myDataC : String!

Now, your data which is in VCA is in VCC with property myDataC, you can use this data as per your need.