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.
In a world where the Swift Protocol is King and Generics are our Queen, we seem to have trouble working with both…realm.io
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 :)