I have this
enum MyEnum {
case one
case two
}
and this
var array:[MyEnum] = [.one]
and later
func add(_ case:MyEnum) {
if array.contains(case) { return }
array.append(case)
}
So far so good.
Then I have added a third option to the enum
enum MyEnum {
case one
case two
case three(user:User)
}
then the line
if array.contains(case) { return }
is giving this error
Referencing instance method 'contains' on 'Sequence' requires that 'MyEnum' conform to 'Equatable'
I guess that the problem is this
contains
can easily see if.one
is equal to.two
or not, so it can check if these elements are onarray
.contains
cannot easily see if.three(user:"bob")
is the same as.three(user:"carl")
, right?
I don't care which user is, I just want to compare if array
has an entry three
or not.
If the array
is [.two, .one, .three(user:"bob)]
and I try to append .three("user:"carl")
I want the line if array.contains(.three("user:"carl"))
to return true.
How do I do that?