[swift-users] Making Error sub-enums Equatable

Zhao Xin owenzx at gmail.com
Mon May 8 05:02:23 CDT 2017


I think you'd better define your own operator, maybe `=~` or something
else. As `==` has already meant something in enum.

Zhaoxin

On Mon, May 8, 2017 at 5:07 PM, Rien via swift-users <swift-users at swift.org>
wrote:

> 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
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170508/2ff840a7/attachment.html>


More information about the swift-users mailing list