EnumMagic
Dynamically initialize enums in Swift
Install / Use
/learn @EricRabil/EnumMagicREADME
EnumMagic
Dynamically construct an enum value based on its case name and an array of associated values
Beware dragons!
This library brazenly works with unsafe bytes and bitcasts it back into the Swift type system. It is compatible with the current Fragile Enum Layout specification.
How to use it
import EnumMagic
enum IntDoubleOrBignum { // => LLVM <{ i64, i2 }>
case Int(Int) // => <{ i64, i2 }> { %Int, 0 }
case Double(Double) // => <{ i64, i2 }> { (bitcast %Double to i64), 1 }
case Bignum(Bignum) // => <{ i64, i2 }> { (ptrtoint %Bignum to i64), 2 }
case Alexis(Int, Double)
case Blank1 // => <{ i64, i2 }> { 0, 3 }
case Blank2 // => <{ i64, i2 }> { 1, 3 }
case ASDFA(Int, Bignum)
}
let dynamicInt = CreateEnum(IntDoubleOrBignum.self, "Int", payload: [5])
let dynamicBlank1 = CreateEnum(IntDoubleOrBignum.self, "Blank1")
let dynamicBlank2 = CreateEnum(IntDoubleOrBignum.self, "Blank2")
let dynamicASDFA = CreateEnum(IntDoubleOrBignum.self, "ASDFA", payload: [6, Bignum(num: 5)])
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
