swift-macro-examples icon indicating copy to clipboard operation
swift-macro-examples copied to clipboard

@OptionSet macro: Choose Your Own Adventure edition

Open DougGregor opened this issue 2 years ago • 0 comments

Make the @OptionSet macro simultaneously support three different forms of option set!

Form #1:

@OptionSet<UInt8>
struct ShippingOptions {
  static var nextDay: ShippingOptions
  static var secondDay: ShippingOptions
  static var priority: ShippingOptions
  static var standard: ShippingOptions
}

Form #2:

@OptionSet<UInt8>
struct ShippingOptions {
  enum Options {
    case nextDay
    case secondDay
    case priority
    case standard
  }
}

Form #3:

@OptionSet<UInt8>
enum Options: UInt8 {
  case nextDay
  case secondDay
  case priority
  case standard

  // macro adds a nested type Set that is the option set
}

DougGregor avatar Mar 08 '23 06:03 DougGregor