Expands hex color string into a floating point value in compile time using Swift Macros

Expands hex color string into a floating point value in compile time using Swift Macros

Muukii

-

Oct 3, 2023

Swift Macros introduced in Swift 5.9 brings the power of compile-time resolving.

I introduce a tiny library that expands a hex color string into SwiftUI.Color initializer code.

muukii/swift-macro-hex-color: A macro that expands a hexadecimal string into a floating-point color value.

#hexColor("#BA43F1")

// Color(.sRGB, red: 0.7294117647058823, green: 0.2627450980392157, blue: 0.9450980392156862, opacity: 1)