Scenario: I want to set a boolean flag within the App Delegate that is accessible from a view controller.
How do I access this flag from any View Controller?
Scenario: I want to set a boolean flag within the App Delegate that is accessible from a view controller.
How do I access this flag from any View Controller?
When you say "within the AppDelegate", do you mean as an instance property? If the app delegate class is AppDelegate, then the instance of it is UIApplication.shared.delegate as! AppDelegate
, and any instance properties it may have can be access through that reference.
But if you simply mean "in the file AppDelegate.swift but outside the AppDelegate class itself", then this variable is a global and can be accessed directly from anywhere.
You simply create the flag inside your delegate and access it like this:
let appDelegate = UIApplication.shared.delegate as! AppDelegate