[swift-users] Why does casting to Any make my forced downcast not crash?
Kim Burgestrand
kim at burgestrand.se
Wed Mar 15 06:51:15 CDT 2017
Found the answer to my follow-up question! It's a known and reported bug:
https://bugs.swift.org/browse/SR-912
Thanks!
On Wed, 15 Mar 2017 at 12:47 Kim Burgestrand <kim at burgestrand.se> wrote:
> On Tue, 14 Mar 2017 at 19:50 Joe Groff <jgroff at apple.com> wrote:
>
>
> It shouldn't. Please file a bug, if you haven't already.
>
>
> Will do! I'll file a bug that casting to `Any` first causes different
> behavior.
>
> Follow-up question, looking at the expression `name as! T`, is it
> expected to cause a nil-unwrapping runtime error when `name == nil` and `T
> == Optional<String>`? Mind you, `(nil as! Optional<String>)` does not
> cause an error.
>
> If the nil-unwrapping error is expected, how can I write it so that it
> doesn't, and instead returns nil?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170315/6afe5adb/attachment.html>
More information about the swift-users
mailing list