fix: wrap #Preview in #if DEBUG to fix CLI build without full Xcode - #62
Conversation
jatinkrmalik
left a comment
There was a problem hiding this comment.
Thanks for the contribution, @slatlasdev! Good catch — the #Preview macro does fail with Xcode Command Line Tools only.
A couple of observations:
-
#if DEBUGmay not fully solve the root issue. ThePreviewsMacrosplugin is missing from Command Line Tools regardless of build configuration. Runningswift build(which defaults to debug) with CLI tools only would still haveDEBUG=trueand hit the same error. In practice this often works becauseswift buildfrom SPM doesn't expand preview macros the same way Xcode does, but it's worth noting. -
Consistency. Looking at the other views in the project (
SettingsView.swift,MenuBarView.swift) — they don't have#Previewblocks, soOnboardingViewis the only one affected. The fix is localized and low-risk. -
No production impact. As you noted,
#Previewblocks are stripped from release builds regardless, so this is purely a dev-tooling improvement.
The change is minimal, correct for the stated problem, and has zero risk to production. 👍
Testing on my local machine - it did seem to fix it for me not having Xcode CLI installed. |
Interesting! Thanks for raising this. |
The #Preview macro relies on PreviewsMacros, which is part of the full Xcode.app IDE and is not available when building with Xcode Command Line Tools only. This causes a build error:
Wrapping the preview block in #if DEBUG ensures it is only compiled in environments where the preview infrastructure is available. This has no impact on the production app — #Preview blocks are never included in release builds.