Compare enums with associated values in Swift

前端 未结 2 1949
忘掉有多难
忘掉有多难 2020-12-21 02:29

For enums with associated values, Swift doesn\'t provide the equality operator. So I implemented one to be able to compare two enums:

enum ExampleEnum{
              


        
2条回答
  •  太阳男子
    2020-12-21 02:49

    Currently there is no way of achieving this without writing out all the cases, we can hope that it'll be possible in a later version.

    If you really have a lot of cases and you don't want to write them all out, you can write a small function that generates the code automatically for you (I've been doing this just recently for something that wasn't possible to refactor)

提交回复
热议问题