When I get to the Live Data section of Chapter 2, I’m bumping into an issue with the
appState. When I try to run Preview, I get "Cannot preview this file - Preview is missing environment object “AppState”.
I figured it was user error on my part, but when I open the final project, I encounter the same issue. I compared my code to that in the finalproject folder and they’re functionally the same and both generate that error when trying to preview ContentView.
Upon further investigation, compiling the app the “old fashioned” way and running it with the play button works fine. It does show the
events.count if you try to view it on the Canvas in live preview mode.
I have mostly avoided using
AppState in the previews to avoid hitting the API usage limit. In some files, I specifically said to delete the preview, but maybe I missed one.
You can add
.environmentObject(AppState()) to the preview, but be prepared for API errors if you do much editing.
Building and running a macOS app is fast, so I tend to use the preview quite sparingly, for small components. Mostly, I just build & run to see what I’m getting.
Thank you for getting back so quickly! This is a fun book to read. I saw a note in the TableView chapter just now re: avoidance of hitting API usage limits.