Difference between associated and raw values in swift enumerations

后端 未结 3 1846
我寻月下人不归
我寻月下人不归 2021-02-12 22:35

Swift enumerations have both associated and raw values. But the use cases of these values is not clear to me. So I would really appreciate if anyone can explain the difference b

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-12 23:20

    Answers by @Airspeed Velocity and @yoAlex5 explain the difference well, but they state that

    enums can have either associated either raw values.

    This is not so for Swift 4 and 5. Here is a good illustration on for having them both in one enum. You'll need default values for raw value initialiser, of course.

提交回复
热议问题