Chapter 3 Appearance Menu

This is so much fun.
I just thought that I would share my alternative to the PickerView and list of buttons for the Appearance menu.

I changed things up a bit for the Appearance menu to replace the Picker with a series of buttons. To get the keyboard shortcuts I added a computed property to the DisplayMode enum

    var shortCut: KeyEquivalent {
        switch self {
        case .light:
            return KeyEquivalent("L")
        case .dark:
            return KeyEquivalent("D")
        case .auto:
            return KeyEquivalent("Y")

I also removed the defined raw values from the enum as you can simply use
displayMode.rawValue.capitalized when you need it to get that same string
That then allows me to use a ForEach loop to display the buttons and then use an SFSymbol of a checkmark, or not depending on whether or not the iteration matches the appStorage version.

Menu("Appearance") {
    ForEach(DisplayMode.allCases, id: \.self) { mode in
        Button {
            displayMode = mode
        } label: {
            if mode == displayMode {
                Text("\(Image(systemName: "checkmark")) \(mode.rawValue.capitalized)")
            } else {
                Text("     \(mode.rawValue.capitalized)")
        .keyboardShortcut(mode.shortCut, modifiers: .command)

Thanks for sharing Stewart. This is an area where there are a lot of possibilities, and you’ve added more to the ones I suggested.