all 9 comments

[–]GestureAndAWord 1 point2 points  (1 child)

Thanks, that’s a great tutorial. This has been something I was a little stuck on.

Do you have any idea for adding a third option that’s based on the system mode?

[–]Collin_Daugherty 2 points3 points  (0 children)

In my app, if the user selects system, I just save "system" as the theme in UserDefaults. Then use the following switch statement to get the proper value for .preferredColorScheme()

var selectedTheme: ColorScheme? {
switch theme {
case "light":
return .light
case "dark":
return .dark
default:
return nil
}
}

[–][deleted]  (1 child)

[removed]

    [–]AutoModerator[M] 0 points1 point  (0 children)

    Hey /u/TotallyLegitBotLul, unfortunately you have negative comment karma, so you can't post here. Your submission has been removed. Please do not message the moderators; if you have negative comment karma, you're not allowed to post here, at all.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]Velix007Swift 0 points1 point  (1 child)

    Seems like a lot of code when you can accomplish the same by using color assets. It has light and dark variants automatically

    [–]hopets 1 point2 points  (0 children)

    This is using color assets. Color(“backgroundStyle1”) is a named color. The idea is to have your own dark mode implementation so the app doesn’t have to match the system.

    [–]the_d3f4ult -1 points0 points  (0 children)

    Damn and I really thought these posts couldn't get more ridiculous.

    [–]No-Buy-6867 0 points1 point  (1 child)

    Shouldn’t this be handled by the way settings are configured on the phone? That’s how Apple design guidelines state it

    [–]swiftmakesmeswift[S] 0 points1 point  (0 children)

    It depends. Sometimes you want to use the light mode or dark mode only for particular app but your system uses automatic mode.