iosappdelegatetintcolorios-darkmodeuitraitcollection

How do I detect dark/light mode changes in my AppDelegate in order to reset global tintColor?


In my AppDelegate, I set the global tint color. How can I be notified when the user enables/disables dark mode in order to reset global tint?

In my AppDelegate, I have:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
    var window: UIWindow?    // To conform with UIApplicationDelegate

    func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [ UIApplication.LaunchOptionsKey : Any ]? ) -> Bool
    {
        window?.tintColor = UIColor.someColor
        ...
    }
}

I need to update the global tint color when dark mode is enabled/disabled. How can I detect this change?


Solution