How to change theme style (User Interface Style) immediately in Swift in iOS 13

This code is instant and there is no need to restart the app!

You just need to call the code on user interaction with notification observer pattern or directly call the function like this:

// Because you are using AppDelegate for this: (But it is going to be deprecated. read the following Note)
(UIApplication.shared.delegate as! AppDelegate).myFunctionThatChangesTheUserInterfaceStyle()

Also note that since iOS 13, the key window is not a part of appDelegate anymore and you should access it from sceneDelegate


We can change user interface style immediately by setting overrideUserInterfaceStyle. I added this code where user can select theme style.

guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
   return
}
appDelegate.changeTheme(themeVal)

I hope this will help others