Swift type erasure

Type erasure in Swift is a beast of it’s own that many, including myself, have a hard time to wrap their head around.

Luckily, there are some very good ressources in the form of blog posts and videos available that explain many aspects of type erasure.

As NatashaTheRobot suggested (MUST WATCH) in the latest issue of “this week in swift”, I watched an excellent talk about “swift type erasure magic”:

Pretty advanced stuff, explained in simple words and nice examples, go check it out :)

Type erased generic Equatable protocol

One of the questions asked in the aforementioned talk was how a generic protocol could adopt the Equatable protocol.

As it turns out, it’s quite simple and only involves a generic operator overload, no need for a “Any*” wrapper:

Happy swifting :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.