Swiftpack.co -  EricRabil/EnumMagic as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Dynamically initialize enums in Swift
.package(url: "https://github.com/EricRabil/EnumMagic.git", from: "1.0.0")


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)])


Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

2 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics