How do I access my view dispatcher from my appDelegate app? (Swift)

I am in AppDelegate and I need to update the web view hosted in my ViewController.

So, I have googled how to call a method / variable from appDelegate, and I found this:

MyViewController* mainController = (MyViewController*)  
self.window.rootViewController

And it looks like it works, but I work in Swift, and I kind of like noob trying to translate this without any luck .. this is my result, but I can't get it to work.

ViewController vc = (ViewController) 
self.window?.rootViewController

What am I doing wrong? How can I access something in my view controller from my appDelegate?

Thank you very much and have a nice day.

+4
source share
1 answer

Try

let viewController = self.window.rootViewController as UIViewController
+5

Source: https://habr.com/ru/post/1569676/


All Articles