Swift development tips and experiences by Tommi Kivimäki

Browse all notes

Preview views in dark mode in SwiftUI

XCode's default template for SwiftUI previews does not define any color scheme. I wanted to have a preview with a dark mode and I found out that I could set the color scheme via .environment modifier.

            @available(iOS 13.0.0, *)
            struct AboutScreenViewSUI_Previews: PreviewProvider {
              static var previews: some View {
                  .environment(\.colorScheme, .dark)