Skip to content

fix: wrap #Preview in #if DEBUG to fix CLI build without full Xcode - #62

Merged
jatinkrmalik merged 1 commit into
VocaHQ:mainfrom
slatlasdev:fix/preview-macro-cli-build
Mar 12, 2026
Merged

fix: wrap #Preview in #if DEBUG to fix CLI build without full Xcode#62
jatinkrmalik merged 1 commit into
VocaHQ:mainfrom
slatlasdev:fix/preview-macro-cli-build

Conversation

@slatlasdev

Copy link
Copy Markdown
Contributor

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:

error: external macro implementation type 'PreviewsMacros.SwiftUIView' could not be found for macro 'Preview(_:body:)'

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.

@jatinkrmalik jatinkrmalik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @slatlasdev! Good catch — the #Preview macro does fail with Xcode Command Line Tools only.

A couple of observations:

  1. #if DEBUG may not fully solve the root issue. The PreviewsMacros plugin is missing from Command Line Tools regardless of build configuration. Running swift build (which defaults to debug) with CLI tools only would still have DEBUG=true and hit the same error. In practice this often works because swift build from SPM doesn't expand preview macros the same way Xcode does, but it's worth noting.

  2. Consistency. Looking at the other views in the project (SettingsView.swift, MenuBarView.swift) — they don't have #Preview blocks, so OnboardingView is the only one affected. The fix is localized and low-risk.

  3. No production impact. As you noted, #Preview blocks 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. 👍

@jatinkrmalik
jatinkrmalik merged commit 4f73e2b into VocaHQ:main Mar 12, 2026
1 check passed
@slatlasdev

Copy link
Copy Markdown
Contributor Author
  1. #if DEBUG may not fully solve the root issue. The PreviewsMacros plugin is missing from Command Line Tools regardless of build configuration. Running swift build (which defaults to debug) with CLI tools only would still have DEBUG=true and hit the same error. In practice this often works because swift build from SPM doesn't expand preview macros the same way Xcode does, but it's worth noting.

Testing on my local machine - it did seem to fix it for me not having Xcode CLI installed.

@slatlasdev
slatlasdev deleted the fix/preview-macro-cli-build branch March 12, 2026 01:04
@jatinkrmalik

Copy link
Copy Markdown
Member
  1. #if DEBUG may not fully solve the root issue. The PreviewsMacros plugin is missing from Command Line Tools regardless of build configuration. Running swift build (which defaults to debug) with CLI tools only would still have DEBUG=true and hit the same error. In practice this often works because swift build from SPM doesn't expand preview macros the same way Xcode does, but it's worth noting.

Testing on my local machine - it did seem to fix it for me not having Xcode CLI installed.

Interesting! Thanks for raising this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants