A full-blown "fourCharCode" macro example

[Not sure this is the right place.]

A year ago, I wrote a wrapper that converted strings to FourCharCodevalues at runtime. I later wondered if making a macro version was possible. The answer is yes, because the "Macros" chapter uses that as an example. So I'm trying out my first macros by doing a FourCharCode macro with error checking, etc.

It's at: < CTMacUser/FourCC: A Swift macro to convert a string to a four-character code - Codeberg.org >.

6 Likes

Cool.

And the next stop is #pascal("…") for Pascal strings, right? (-:

[Not sure this is the right place.]

Community Showcase is a good option for stuff like this.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

3 Likes

Ah the days of Str255!

Very cool. I did the same a while back (private repo), but have since moved to a dedicated struct since I wanted things to be strongly typed.

I also wanted to avoid the runtime logic of String to Uint32 so created a utility application to generate code for constants which takes as input a variable name and the 4CC. e.g. folderType and ƒldr produces:

	/// <#T##Description#>.
	///
	/// `'ƒldr' (0xC46C_6472)`.
	static let folderType = IIFourCharCode(value: 0xC46C_6472)