[Pitch] `@OptionSet` macro

How does that reconcile with the fact that modern swift-only framework from Apple (SwiftUI) uses OptionSets massively? Being swift-only there's no Obj-C compatibility concerns in this case, just these:

  • use bits for flags instead of full bytes to save space (compiler packing bools to bits is a pipe dream yet).

  • keep the structs that hold option sets POD (if they were POD already)

  • use compact syntax to represent set values, like so:

      SubView()
          .padding([.top, .trailing], 10)
          .padding(.all.subtracting(.top), 20)
    
      // vs somewhat mildly heavier:
    
      SubView()
          .padding(.init(top: true, trailing: true), 10)
          .padding(.init(top: true, trailing: true, bottom: true), 20)
    
5 Likes