I have a ViewController called : ViewController I have a AppDelegate called : AppDelegate
They are not made programmatically, they are are just as default when you create a new app in swift.
Imagine that in the ViewController I have:
class ViewController: UIViewController {
var animal = "dog"
}
For example, I want to print animal value when the app goes in the background. So in the AppDelegate i have:
func applicationDidEnterBackground(_ application: UIApplication) {
var ViewController: ViewController!
print("animal = \(myViewController.animal)")
}
I am getting : fatal error: unexpectedly found nil while unwrapping an Optional value
How can I access that value from my AppDelegate ? PS: I tried the first 2 pages of google/StackOverflow
var ViewController: ViewController!must bevar controller = ViewController()and thenprint("animal = \(controller.animal)")