[swift-users] Making Error sub-enums Equatable

Rien Rien at Balancingrock.nl
Mon May 8 04:07:42 CDT 2017


I’d love to know if there is a better way, but a ‘switch’ or 'if case' is the only way I know.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl - A server for websites build in Swift






> On 08 May 2017, at 11:01, Rick Mann via swift-users <swift-users at swift.org> wrote:
> 
> Seriously, I've been googling this for a half-hour, and I can't find an answer (everything that comes up is for ErrorType, absolutely nothing for Error).
> 
> I have an enum:
> 
> enum MyErrors : Error
> {
>    case one(String)
>    case two
>    case three(String)
> }
> 
> let a: MyErrors = .one("foo")
> let b = .two
> let c = .towo
> 
> I want to compare them with ==, and I don't care about the associated types. I can't for the life of me figure out how without an exhaustive switch statement in a == definition. Is that the only way?
> 
> -- 
> Rick Mann
> rmann at latencyzero.com
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list