On page 104 (in v.1.1.0), when adding conditional for ‘if defaults.bool(forKey: “show_hint”)’, it worked fine when running on MacCatalyst (My Mac), but when I went back to trying to run the Preview for an iPhone, the app kept crashing. It seemed to have a problem with the ‘defaults’ property (UserDefaults) when the target was not MacCatalyst.
But I figured out a cure! In ContentView.swift, above the ContentView struct declaration, I added the following compiler conditional:
#if targetEnvironment(macCatalyst)
let ISMACCATALYST = true
#else
let ISMACCATALYST = false
#endif
Then in ContentView’s body, I wrapped the ‘show_hint’ conditional inside an ISMACCATALYST conditional, like this:
if ISMACCATALYST {
‘the show_hint if-else conditional’
} else {
Slider(value: $currentValue, in: 0.0…100.0, step: 1.0)
}
That did the trick. Just thought I’d put this out there in case anyone else ran into this.