I know that almost the same question was asked before, but I can not comment on it, because I'm here for a new one. That is why I am posting a separate question. Also my question is a continuation of the previous question asked and aims at a more general solution. This is a link to a previous question: How to check equality of Swift enumerations with related values
I want to check equality in an enumeration with related values:
enum MyEnum { case None case Error case Function(Int)
I tried to configure the overload function as follows
func ==(a: MyEnum, b: MyEnum) -> Bool { switch (a,b) { case (.Function(let aa), .Function(let bb)): if (aa==bb) { return true } else { return false } default: if (a == b) { return true } else { return false } } }
This does not give a compile-time error, but does not work with bad_exec in a running process. Most likely because testing a == b in the default case calls this function again. The .Function part works as expected, but not everything else ... So, the list of cases is somewhat longer, how can I check cases that do not have an associated value for equality?
source share