Swift - Passing value back to ViewController using protocol and delegate
<p>I'm new to swift and my problem right now is I want to pass the value from RoutePreviewController page back to display on ViewController page after clicking on the Navigate Button. As below picture, you can see that the RoutePreviewController is not directly segue from the ViewController.    </p>

<p><a href="http://i.stack.imgur.com/pWjmy.png" rel="nofollow">This is my story board of the swift project on xcode</a></p>

<p>However, I tried using protocol and delegate in the code.</p>

<p>Here are codes that I have add to the ViewController (MainPage) </p>

<pre><code>protocol HandleSelectedPath{
    func selectedPathDraw(selectedRoute:[(line:Int?,node:Int,time:Double)])
}
</code></pre>

<p>in viewDidLoad of ViewController</p>

<pre><code>    let routePreviewPage = storyboard!.instantiateViewControllerWithIdentifier("RoutePreviewController") as! RoutePreviewController
    routePreviewPage.handleSelectedPathDelegate = self
</code></pre>

<p>and an extension outside the ViewController class</p>

<pre><code>extension ViewController : HandleSelectedPath{
    func selectedPathDraw(selectedRoute:[(line:Int?,node:Int,time:Double)]){
        print("7687980")
        selectedPath = selectedRoute
        routeDraw()
    }
}
</code></pre>

<p>And in RoutePreviewController, I have delegation of the protocol.</p>

<pre><code>var handleSelectedPathDelegate: HandleSelectedPath? = nil 
</code></pre>

<p>and the Navigate button action </p>

<pre><code>@IBAction func navigateButtonAction(sender: AnyObject) {
    handleSelectedPathDelegate?.selectedPathDraw(previewPath)
    dismissViewControllerAnimated(true, completion: nil)
    definesPresentationContext = true
}
</code></pre>

<p>As a result, after clicking the Navigate button, it does send me back to the ViewController page but the selectedPathDraw function of the protocol is not performed. I also tried printing some random string but nothing came up as an output.</p>