QizhKit uses an environment-based build configuration to conditionally enable HDR-aware color APIs. This document explains how the feature works, how to enable it, and what code paths are affected.
The package checks for the QIZHKIT_ENABLE_HDR environment variable at build time:
- Variable name:
QIZHKIT_ENABLE_HDR - Valid values:
1ortrue(case-insensitive fortrue) - Default behavior: HDR APIs are disabled when the variable is not set
Set the environment variable before building:
# In Terminal (macOS)
export QIZHKIT_ENABLE_HDR=1
swift build
# Or inline
QIZHKIT_ENABLE_HDR=1 swift buildIn Xcode, you can set the environment variable in your scheme's Run/Build settings.
When QIZHKIT_ENABLE_HDR is set to 1 or true, the package adds the following Swift compiler define:
.define("RESOLVED_HDR_AVAILABLE")This define is applied to both the main QizhKit target and the QizhKitTests target.
The RESOLVED_HDR_AVAILABLE define controls access to HDR-aware SwiftUI APIs introduced in iOS 26 and macOS 26:
The Color.resolvedComponents(of:in:) function uses the define to choose between:
-
With
RESOLVED_HDR_AVAILABLE: UsesColor.resolveHDR(in:)when available (iOS 26+, macOS 26+), falling back toColor.resolve(in:)on earlier platforms. -
Without
RESOLVED_HDR_AVAILABLE: Always usesColor.resolve(in:)(the pre-HDR API).
#if RESOLVED_HDR_AVAILABLE
if #available(iOS 26.0, macOS 26.0, *) {
color.resolveHDR(in: environment).resolvedComponents
} else {
color.resolve(in: environment).resolvedComponents
}
#else
color.resolve(in: environment).resolvedComponents
#endifThe following extensions are only compiled when RESOLVED_HDR_AVAILABLE is defined:
Color.ResolvedComponents.init(linear:Color.ResolvedHDR)– Initializer from HDR-resolved colorColor.ResolvedHDR.resolvedComponents– sRGB components from HDR-resolved colorColor.ResolvedHDR.linearResolvedComponents– Linear-light components from HDR-resolved color
HDR-aware APIs require:
- iOS 26.0 or later
- macOS 26.0 or later
On earlier platforms, the code gracefully falls back to the standard Color.resolve(in:) API even when RESOLVED_HDR_AVAILABLE is defined.
This approach allows:
-
SDK Compatibility: Projects using older SDKs (before Xcode 26) can still build QizhKit without encountering unknown symbol errors for
Color.ResolvedHDRandColor.resolveHDR(in:). -
Opt-in HDR Support: Developers who want HDR-aware color resolution can explicitly enable it when their toolchain supports the new APIs.
-
Consistent Build Behavior: The same codebase works across CI environments, local development setups, and production builds with different SDK versions.
The configuration is implemented in Package.swift:
import Foundation // ← for ProcessInfo
/// Decide if HDR APIs should be enabled for QizhKit.
let isHDREnabled: Bool = {
if let value = ProcessInfo.processInfo.environment["QIZHKIT_ENABLE_HDR"] {
return value == "1" || value.lowercased() == "true"
}
return false
}()
/// Base swift settings for QizhKit.
var qizhKitSwiftSettings: [SwiftSetting] = [
// ... other settings
]
/// Add the define only when HDR is explicitly enabled.
if isHDREnabled {
qizhKitSwiftSettings.append(.define("RESOLVED_HDR_AVAILABLE"))
}Related Files:
Package.swift(lines 5-28)Sources/QizhKit/Extensions/Color+/Color+brightness+luminance.swiftTests/QizhKitTests/ColorBrightnessLuminanceTests.swift