[swift-evolution] [Accepted] SE-0072: Fully eliminate implicit bridging conversions from Swift

Charles Srstka cocoadev at charlessoft.com
Fri May 6 22:20:24 CDT 2016


> On May 6, 2016, at 3:15 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On May 6, 2016, at 12:21 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Does this affect the ability to use "x as? Int" (and similar) when x is an NSNumber?
> 
> No, this only affects compile-time implicit conversions. I proposed changing the runtime behavior of dynamic casts in SE-0083:
> 
> https://github.com/apple/swift-evolution/blob/master/proposals/0083-remove-bridging-from-dynamic-casts.md <https://github.com/apple/swift-evolution/blob/master/proposals/0083-remove-bridging-from-dynamic-casts.md>
I’d just like to throw in that the ability to use “x as? Int” when x is an NSNumber is terrible.

let num: AnyObject = NSNumber(int: 5)

let int = num as? Int		// 5
let float = num as? Float		// 5
let int32 = num as? Int32	// nil!

Completely unexpected failure, and you’ll never know about it until runtime.

Charles

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


More information about the swift-evolution mailing list