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
版权声明:本文标题:Is there any way to take control of the shorthand syntax for enum literals in Swift? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741988346a2408820.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论