logoalt Hacker News

JackYoustrayesterday at 11:02 PM3 repliesview on HN

Adding on, its also a bit much to say that Swift has a good level of sugar and reference an enum of all things. Swift's union type story is so poor that, instead of properly modeling state, people to this day still use masses of optional types in their views rather than an enum because actually using swift enums and protocols is so painful.


Replies

vor_today at 6:26 AM

> actually using swift enums and protocols is so painful.

In what way? My understanding is they're widely used and encouraged.

show 1 reply
frizlabtoday at 12:14 AM

I don’t which Swift developers you are talking to, but let the record know I don’t and use enum quite a lot. And I don’t find it particularly painful though a bit verbose at times.

show 1 reply
nielsbottoday at 12:08 AM

I don't think it's horrible, but I really do wish they would copy TypeScript here.

Let me do this:

    const x: String | Int
Instead of

    enum MyEnum {
        case string(String)
        case int(Int)
    }
There's an existing proposal for this here:

https://forums.swift.org/t/re-proposal-type-only-unions/7270...

show 2 replies