I am in my AppDelegate and I need to refresh the webview placed in my ViewController.
So I've 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'm working in Swift and I'm kinda of a noob trying to translate this without any luck.. this is my result but I can't manage to make it work..
ViewController vc = (ViewController) self.window?.rootViewController What am I doing wrong? How can I access to something in my viewcontroller from my appDelegate?
Thank you very much and have a nice day
vcvariable incorrectly - that isn't how you declare a variable with a type in Swift. b) you are castingself.window?.rootViewControllertoViewControllerwhich is incorrect, and also the wrong type. To be honest, you really need to spend more time reading the Swift introductory references rather that asking for direct code translations on SO. These are very basic concepts.NSNotificationsfor this kind of things.