简体   繁体   中英

Understanding Equatable in swift 3?

I have an array of enum which I need to delete one of the Enum. I have written generic remove operation based on here . We usually conform Equatable to Struct. So I am curious how Equatable will behave in Enum. If It is not a right way to write generic remove operation for collection of Enum array, then what will be the right one?

enum APIEndPoints: Equatable {
   case image
   case email
   case others
}

By definition, two enums of the same type are equal if they are of the same case. Thus .image is equal to .image , for example. That is why you are able to test enum instances against one another using the == operator to find out what case something is. Indeed, this fact is sort of the point of enums.

(This, by the way, is also why enums cannot have stored properties. Two .image instances with different stored values for the same property would not be equal. And that would completely defeat the purpose of enums.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM