I looked around for discussions on why Swift doesn't have macros, but so far everything I've seen focuses on defining constants and checking for build flags, and of course Swift has ways to accomplish both. But what about for this kind of use case?
There is of course the "dangerous if misused" angle, but code duplication is a particular pet peeve of mine and I'd really like some way of cleaning that up.
Macros are something that has been discussed and many people (myself included) want them. It's just not something people have really started hammering out. I think most people don't want another c-preprocessor. We want proper macros that could manipulate the AST during compilation.
In the spirit of ignoring the general question and focusing on the example, perhaps an enum with a String raw value could be used in some of these cases, e.g. ignoring all the bad name choices because I'm not sure exactly what the context of your code is:
@dynamicMemberLookup Is tempting, but I'd rather be explicit about which colors are available and get compile time checking. The enum I think is appealing because it's a way to explicitly categorize the colors.
Actually, with a good macro system, a few language features could be implemented in the Standard Library, resulting in a simpler language: Codable, Equatable, Hashable, CasseIterable synthesizing.
When we get around to seriously considering a macro system, I think that we should start by looking at the places where the compiler auto synthesizes stuff and try to generalize it, and move these features into the stdlib:
Property macros (like the old property behaviors proposal), to generalize lazy and didSet/willSet observers.
Protocol member synthesis macros to generalize hashable, equatable, allCases, etc.
perhaps others
Look at the stuff currently being gyb'd in the standard library and sort it out by use cases.
At the end of this, I think there will be room for a general hygienic expander of some sort, e.g. a "compile time #for loop" that iterates over compile time defined lists - which could provide functionality similar to the .def files in the swift/llvm/clang codebases.
That said, I personally prefer to wait on that general feature until we explore the other structured approaches (along with related things like constexprs) and when there is a specific really important use case driving it.