Reputation: 1207
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
Upvotes: 4
Views: 5832
Reputation: 5925
Try
let viewController = self.window.rootViewController as UIViewController
Upvotes: 6