In View Controller A,
var completionBlock: (((String) -> ()))? = nil
& I am calling the completion block like(ViewController A):
if let block = completionBlock {
block("block data to pass")
}
I don't want to pass the completion data to ViewController B, instead i want to pass to ViewController C which is presenting from ViewController B.
In simple words, i want to pass the closure data to from ViewController A to ViewController C.I know how to pass data with delegates, just curious with closures?
How can we achieve that?
If this block is something that you need to pass between several viewControllers, you have few options:
1- Pass closure as a variable: Create a variable on each new ViewController in the middle of VC-A, VC-C and pass them in between
for example:
2-Pass via Notification Center You can pass this block from Any View Controller to Any Other:
3-Access from shared object Use a singleton design and create a static shared object and read/write to the object from different view controllers
This is just a sample code i quickly wrote for you, you can modify objects based on your need. Hopefully will address your problem.