[swift-users] returning an array of Protocol-conforming objects from a function

Ryan Walklin ryan at testtoast.com
Mon Jan 25 21:36:39 CST 2016


Hi All,

I have a function which returns a closure, which then returns an array of objects conforming to a protocol. 

ie. 

protocol MyProtocol {}

extension Float: MyProtocol {}
extension OtherType: MyProtocol {}

When I try to return an array of Floats, I get the error “Cannot convert value of type '[Float]' to closure result type ‘[MyProtocol]”.

Other struct-based types work fine.

Is this not possible with standard library types?

Regards,

Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160126/094415e3/attachment.html>


More information about the swift-users mailing list