[swift-users] Assigning [Int] to [Any] crashes Swift 2.2

Jens Alfke jens at mooseyard.com
Thu Apr 14 11:24:09 CDT 2016

> On Apr 14, 2016, at 9:00 AM, Joe Groff <jgroff at apple.com> wrote:
> This is a known bug. Converting arrays of value type to arrays of protocol type is not supported—only class covariance is supported with containers—but the compiler fails to catch some cases. 

Thanks for the info!

I found that if I use AnyObject instead of Any, it does work correctly. Is that because AnyObject isn’t a protocol? Or because conversion to AnyObject is a ‘magic’ case that uses Obj-C bridging?

My intuition is that [Any] will be more efficient than [AnyObject] for primitive values like numbers, because the AnyObject conversion boxes the value into a heap object, while converting to Any doesn’t. Or is that incorrect?

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

More information about the swift-users mailing list