@SceneStorage not working on macOS

Hi,

using the following ContentView in a SwiftUI app on macOS I would expect that the state of the toggle persists across application launches:

struct ContentView: View {
  @SceneStorage("Toggle") var onOrOff: Bool = false

  var body: some View {
    VStack {
      Toggle("Will it persist?", isOn: $onOrOff)
        .padding()
    }
  }
}

To my surprise it does not persist. Am I wrong about how @SceneStorage should work? (I am trying this on the lates macOS/Xcode versions)

Does @SceneStorage work for anybody on macOS?

Thanks for your feedback!

Cheers, Michael

Seems like nobody is using SwiftUI on macOS :-(

So far I tried it on three different machines (all running the lates macOS/Xcode). One even installed from scratch, to be sure it's nothing in my installation. So my guess is, that it's just broken. I filed FB10011754 for this.

Anyway if somebody has @SceneStorage working on macOS I would like to hear from you and maybe figure out what's different that makes it work.

Your code works fine on the following configuration:

  • macOS 12.4 (21F79)
  • Xcode Version 13.4 (13F17a)

Checkbox selection is restored on re-run

Give it like a few seconds for it to be persisted or tap on a different app for it to save the state.

I'm having a similar issue on Mac with Xcode 15

Really, Apple should be ashamed, im disgusted by this tbh

@SceneStorage not working on macOS
 
 
Q