I want to change my ViewController's background color. Within the view controller, I can write self.view.backgroundColor = UIColor (red: 0, green: 0.0, blue: 0.5, alpha: 1.0)
.
However, I need to change it from AppDelegate. According to this answer, accessing properties of the ViewController in AppDelegate works like this:
1) Setting a global variable: var myViewController: ViewController!
2)
var theViewController = ViewController()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.myViewController = theViewController
So that
self.myViewController.view.backgroundColor = UIColor (red: 0, green: 1.0, blue: 0.5, alpha: 1.0)
should change the background color. However, it doesn't. How can I change the ViewController's background color from AppDelegate?