[swift-evolution] Why is AnyObject's bridging so weird in Swift 3?

Charles Srstka cocoadev at charlessoft.com
Mon Dec 12 14:16:56 CST 2016


> On Dec 12, 2016, at 2:12 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
> 
> print((c as AnyObject?)?.bar() as Any) // Optional(6)
> print((s as AnyObject?)?.bar() as Any) // crash! -[_SwiftValue bar]: unrecognized selector sent to instance 0x5432109876543210

All right, immediately after sending this, I realized what was wrong with this; bar() should have been bar?(). If the question mark is added, the last line returns nil instead of crashing. The rest of my questions still stand, and we can add to the list why the above doesn’t raise a compiler warning.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161212/37586955/attachment.html>


More information about the swift-evolution mailing list