.environmentObject(AppData()) modifier to the preview struct.
Recently, I ran into an issue where I couldn’t preview my changes after introducing non-static content. The error in question is
Cannot preview in this file -- The operation couldn't be completed. (BSServiceConnectionErrorDomain error 3.)
Naturally the next step is running the diagnostics which was a bit hairy because the
Reveal in Finder didn’t actually open the correct directory.
After a little digging the I was able to find the
previews-diagnostics-... directory and thus the actual crash log. The crash log was a bit more straightforward and reveal the issue just not where I needed to add the
.environmentObject(AppData()) modifier. The app already had the
.environmentObject(AppData()) added to the top view ContentView but not the Preview
Turns out all that was missing was adding
.environmentObject(AppData()) modifier to my preview. Note, this ends up being added to any view that uses the view in question.