Swift - Update a value in RootViewController from AppDelegate when the app comes to background state
As others have noted, you can use the Notification framework to do this from within your view controller so your appDelegate does not need to reference your view controller. Add a line like this in your controller:
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(appWillEnterForeground),
name: NSNotification.Name.UIApplicationWillEnterForeground,
object: nil
In Swift 3 the syntax changes slightly:
NotificationCenter.default.addObserver(self,
selector: #selector(appWillEnterForeground),
name: NSNotification.Name.UIApplicationWillEnterForeground,
object: nil)
In Swift 4.2 the syntax changes again:
NotificationCenter.default.addObserver(self,
selector: #selector(appWillEnterForeground),
name: UIApplication.willEnterForegroundNotification,
object: nil)
then define the function you name in the selector:
@objc func appWillEnterForeground() {
//...
}