In Xcode with Swift, if you use a lowercase enum for namespacing constants you get ideal syntactic sugar and bonus syntax highlighting at call sites.

The lowercase-enum trick composes well* with static dynamic member lookup + static key paths to build a platform-agnostic design system full of constants that can then get projected to the platform type.

*subjective

I made a document on my website to catalog the lowercase enum idea.

https://kylehugh.es/documents/swift-namespace-lowercase-enum/

Namespaces in Swift Using Lowercase Enums

A technique for creating namespaces in Swift using caseless lowercase enums.

@kyle @mattiem would it be too much additional work to do this instead?

extension TimeInterval {
public static let animation = Animation()
public enum Animation {
public let `default`: TimeInterval = 0.25
public let minorTweak: TimeInterval = 0.15
public let pop: TimeInterval = 0.35
}
}

@miguelcabeca @mattiem Not too much work, no.

But, technically, this needs to be a `struct` so it can be instantiated. And then it needs a private initializer to communicate that it shouldn't be instantiated outside of this limited scope. So now this has become a many-step pattern every time we want to replicate it. Things to remember, things to get wrong, levels of misdirection.

What I proposed, although it has its own edges, minimizes the levels of misdirection and the number of rules.

@kyle @mattiem right, I missed that. I see the elegance of the solution now, but the breaking of convention makes me uneasy. Probably enough to keep me away from it. Thank you for taking the time to write it up though!

@kyle @mattiem ok, I gave it one more try, this time in front of a computer in Xcode instead of typing in my phone. What about this?

extension TimeInterval {
public static let animation = Animation.self
public enum Animation {
public static let `default`: TimeInterval = 0.25
public static let minorTweak: TimeInterval = 0.15
public static let pop: TimeInterval = 0.35
}
}

@miguelcabeca @kyle @mattiem Have been avoiding chiming in because I didn’t want to harshen anyone’s vibes, but I think generally this solution is what I would recommend. It creates the same namespace/chaining/property syntax, but with the ability to provide intermediate state which you would otherwise have to resort to `static` for if you use an enum.
@mergesort @miguelcabeca @mattiem There are a lot of ways to get that syntax with more features but none, IMO, whose cognitive load is so low. When I have 150 of these, maintaining identical structs-and-properties-and projections, or whatever the implementation is, weighs on me in an intangible way.
@kyle @miguelcabeca @mattiem That’s fair. FWIW I’ve moved from the enum approach you wrote about to structs over the years and overall have seen negligible mental overhead, but everybody’s different.
@mergesort @miguelcabeca @mattiem I’m like a Ferrari, I need high octane gas.
@kyle @miguelcabeca @mattiem Makes sense. You would go from 0 to 60 in record time but can’t drive on most streets.