Closed pushkarnk closed 6 years ago
The way you would do this in Swift is by using an Optional, no?
Yes, I agree that using an Optional is another way. But won't that increase the number of checks?
No. In fact, using an Optional enum
is exactly isomorphic to what you've asked for: the Swift compiler will synthesize an extra enum
case to be the "not present" value in any situation where you're using the Optional.
Thanks for the suggestion!
I have been working with SwiftNIO over the last couple of days. In the previous networking framework that we used, there was support to initialise vars tracking the
HTTP status code
with a dummy value likeunknown = -1
.The only way to do something similar with HTTPResponseStatus is by using the
custom
value. However, IMO, simple checks tend to become bigger because.custom
has associated values.If a dummy value were added to the HTTPResponseStatus enum, things may be easier to express!
If there are alternate ways to achieve this without an addition to the enum, I'll be happy to know what they are!