Unable to change the dark mode on the SwiftUI

Viewed 3068

I tried toggle the dark mode, I know Swift 4 or 5 I use the code:

overrideUserInterfaceStyle = .dark

But in SwiftUI, seem nothing way I can do that...how can I toggle the dark mode rest of app? I tried do many method and search everywhere but couldn't find any luck. Even I tried use didSet but no luck, it give me the error.

Any suggestion?

1 Answers

If you want to force dark mode for the whole app you can add the User Interface Style to the Info.plist and set it to Dark

enter image description here

You can also add the following line to the Scene/App Delegate

window?.overrideUserInterfaceStyle = .dark

Related