[swift-users] Using 'SomeProtocol' as a concrete type conforming to protocol 'SomeProtocol' is not supported

Brandon Knope bknope at me.com
Wed Dec 28 18:10:35 CST 2016


Aren’t I losing the ability to enforce what is going into this enum’s associated value then?

Brandon

> On Dec 28, 2016, at 7:05 PM, Nevin Brackett-Rozinsky <nevin.brackettrozinsky at gmail.com> wrote:
> 
> It will work if you change the enum declaration to:
> 
> enum ElementNode<T>
> 
> In other words, let the enum hold arbitrary unconstrained associated types, and then make your APIs utilize instances of the enum with the associated type constrained to a protocol.
> 
> The specific example you provide is essentially equivalent to:
> 
> var childElements = [Element?]()
> 
> Nevin
> 
> 
> On Wed, Dec 28, 2016 at 6:41 PM, Brandon Knope via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> I don’t understand why this is a problem
> 
> protocol Element {
>     
> }
> 
> enum ElementNode<T: Element> {
>     case element(T)
>     case empty
> }
> 
> var childElements = [ElementNode<Element>]()
> 
> I need to represent an array of my nodes that could be multiple kinds of elements
> 
> Is there a workaround?
> 
> Brandon
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161228/1c21269e/attachment.html>


More information about the swift-users mailing list