Contents

davdroman/swiftui-color-macros

Compile-time-checked SwiftUI Colors

Features

  • hex: accepts RGB, RGBA, RRGGBB, RRGGBBAA, with or without # or a 0x prefix.
  • 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.Color literal (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.

Installation

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.

Package Metadata

Repository: davdroman/swiftui-color-macros

Stars: 7

Forks: 0

Open issues: 1

Default branch: main

Primary language: swift

License: MIT

README: README.md