[swift-evolution] Question about heterogeneous collections

Jason Sadler jason.sadler at gmail.com
Tue Mar 29 17:19:53 CDT 2016


Hi folks,

I have an issue with using a heterogeneous array of objects conforming to a protocol - I want to write an extension on Array (or CollectionType) that applies only when Element : MyProtocol, but I can’t call methods in that extension from an instance of [MyProtocol] because "Using ‘MyProtocol' as a concrete type conforming to protocol ‘MyProtocol' is not supported”

(For more background, my full use case can be seen in this gist: https://gist.github.com/sadlerjw/2cc16b4375b02fe7f400)

I’ve asked about this on swift-users (https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160321/001560.html) and got some good workarounds but no one was able to provide me with information on any future plans in swift to address this issue - whether that’s making protocols conform to themselves, or some other improved approach to heterogeneous collections. I wonder if anyone here can shed some light on this? (I’m new to the mailing lists, sorry!)

Thanks

Jason


More information about the swift-evolution mailing list