Agreed, but I'm sure lots of user code depends on it (e.g. when extracting
numeric values from property lists). If it stopped working, wouldn't these
"as?" casts silently start returning nil where they didn't before?
On Fri, May 6, 2016 at 8:20 PM Charles Srstka <cocoa...@charlessoft.com>
wrote:

> On May 6, 2016, at 3:15 PM, Joe Groff via swift-evolution <
> swift-evolution@swift.org> wrote:
>
>
> On May 6, 2016, at 12:21 PM, Jacob Bandes-Storch via swift-evolution <
> swift-evolution@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
>
>
> 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
>
>
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to