1

I am having trouble getting an updated preview when using @EnvironmentObject in my Swift project. In the simulator it works fine, but previewing is not. The error it shows is following:

ASET - Audio System Engineer Tools crashed due to missing environment of type: UserSettings. To resolve this add `.environmentObject(UserSettings(...))` to the appropriate preview.

However, when I try to add it, it keeps on coming with the same issue. Anyone have some helpful advise or solution?

Fabian H.
  • 458
  • 4
  • 11

1 Answers1

14

Found the answer which was already posted on stack overflow: instead of just putting it in the preview struct, I had to declare it like this, which makes the preview update without any issues:

struct CalculatorView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .environmentObject(UserSettings())
    }
}
Fabian H.
  • 458
  • 4
  • 11