ColorMacros is a bundle of expression macros that turn the color tokens you copy from
Figma/Sketch into compile-time SwiftUI.Color literals:
import SwiftUI
import ColorMacros
let brand = #Color(hex: "#FF9900")
let overlay = #Color(hex: "0x336699CC")
let grass = #Color(rgba: 154, 234, 98, 1)
let warning = #Color(hsla: 32, 100, 50, 0.8)
let accent = #Color(hsba: 200, 60, 80, 0.65)hex:acceptsRGB,RGBA,RRGGBB,RRGGBBAA, with or without#or a0xprefix.rgb:/rgba:accept 0–255 integer channels, optionally plus opacity (0–1).hsl:/hsla:accept degrees/percentages, matching what design tools output.hsb:/hsba:cover hue–saturation–brightness (%), again with optional opacity.- Every variant emits a
SwiftUI.Colorliteral (no runtime helpers) and validates inputs at build time.
Example diagnostic:
#Color(hex: "#12345")
┬───────
╰─ 🛑 Hex literals must contain 3, 4, 6, or 8 digits, but found 5.
Add the package to your project:
dependencies: [
.package(url: "https://github.com/davdroman/swiftui-color-macros.git", from: "0.1.0")
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "ColorMacros", package: "swiftui-color-macros")
]
)
]Then import the module alongside SwiftUI wherever you need the macro.