[swift-evolution] Getting a list of protocol conformers

Rick Mann rmann at latencyzero.com
Tue Nov 15 22:17:34 CST 2016


> On Nov 15, 2016, at 19:53 , Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> I would like to be able to get, at runtime, an array of all types conforming to a particular protocol.  (Similarly, I would like to be able to get an array of all subtypes of a given type).  Is this in the generics manifesto?  If not, can it be added?  What is the timeframe?
> It seems to me, that the compiler should actually already have this information, and it is just a matter of keeping it around when it is requested.  I could be wrong about that though...
> Why do I want this?  It would make a lot of things like plug-ins and extensible factories possible (and much easier where they are possible).  For example, you could add a new type to a factory (without the factory having to be coupled to it) just by adhering to a protocol.  It would also make building a swift version of NSCoding much easier.
> I have asked for other, more complicated, language features (e.g. handler funcs) to make those possible before, and I still want them (since I have used them in other languages and it was enormously powerful), but I realized that I should actually be able to make most of those features in a library myself (albeit a bit slower than the compiler could) if I am able to get a list of conforming types at runtime (and then call static methods on those types).
> Also, if there is a way to do this now (even if it is slow), I would appreciate the help…
> Thanks,
> Jon
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

Rick Mann
rmann at latencyzero.com

More information about the swift-evolution mailing list