Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-15 Thread Ole Begemann via swift-users
One way to do this in Swift is a method called type erasure. Type erasure means you create a new type that wraps any value whose concrete type you want to erase. This new type also conforms to the protocol. By convention the type is named Any... (compare AnyIterator and AnySequence in the

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-15 Thread Glen Huang via swift-users
This sounds like the right approach! However, as I experimented with AnyHashable more, I found out that after converting a concrete type to it, I could still convert back using “as”: AnyHashable(Foo()) as! Foo I guess that’s not the case with AnyNamed? I tried to imitate AnyHashable: struct