Call function in UIViewController from an extension
<p>I have a UIViewController which loads up some json data from the server. If the server is down or the user has data turned off I throw up an alert telling the user such. This is done using a UIAlertController. This works great. So I put this into an extension since it is used by all UIViewControllers which need data. Now the UIAlertController has an action set as well</p>

<p>Alert code</p>

<pre><code>extension UIViewController {    
func connectionLost(){
    var message = "Your device has lost connection to the server. Check that you have a valid internet connection and then retry."

    let alertController = UIAlertController( title: "Connection Lost",
                                             message: message,
                                             preferredStyle: .alert)
    let retryAction = UIAlertAction(title:"Retry", style: .default, handler: {
        action in

        //call function in the viewcontroller that raised this alert to reload the data
    })
    alertController.addAction(retryAction)
    self.present(alertController, animated: true, completion: nil)
}
}
</code></pre>

<p>When the user taps the retry button I want to call a function in the uiviewcontroller that raised the alert. </p>

<p>I tried creating a delegate in the extension but struggled with getting it wired up like you do in a class. What sort of approaches are there to call a function from an extension in the viewcontroller that raised the alert?</p>