admin管理员组

文章数量:1316019

In my app we have a enum that we do not have a lot of control over as it is auto generated.

It ends up looking like

enum State {
  case known(KnownStates)
  case unknown(UnknownState?)
}
enum KnownStates {
  case AK
  case AL
  case ON
  case WA
  ....
}

What I am wondering is if there is a way to regain the shorthand syntax of being able to do something like this

let knownState: KnownStates = .WA

But with my more complex structure

let state: State = .WA

I did try writing

   extension State {
     init(_ state: Components.Schemas.KnownStateOrProvince) {
        self = .KnownStateOrProvince(state)
     }
   }

But that does not allow the shorthand syntax to compile.

Obviously if these types weren't auto generated I would make something like

enum State {
  case AL
  case AK
  case ON
  case unknown(String?)
}

But I do not have that option.

本文标签: Is there any way to take control of the shorthand syntax for enum literals in SwiftStack Overflow