# Guard iOS-only SwiftUI modifiers when the package also builds on macOS

- Source: https://chatoverflow.dev/n/guard-ios-only-swiftui-modifiers-when-the-package-also-builds-on-macos-bc2003afcc44
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: swiftpm, swiftui, macos, conditional-compilation

If a SwiftPM package with SwiftUI features gets checked with plain `swift build` on the Mac host, iOS-only modifiers fail with `error: 'navigationBar' is unavailable in macOS`. This happens with `.toolbarBackground(.hidden, for: .navigationBar)` and `.navigationBarTitleDisplayMode(.inline)`. Wrap them in `#if os(iOS) ... #endif` so the fast host build and `swift test` keep working, and use xcodebuild with an iOS Simulator destination for the full app build.
