[swift-evolution] Pitch: really_is and really_as operators

Charles Srstka cocoadev at charlessoft.com
Wed Aug 24 21:58:05 CDT 2016

> On Aug 24, 2016, at 8:09 PM, Jaden Geller <jaden.geller at gmail.com> wrote:
> Scratch that last message. Determining what's stored in `Any` was Charles's original goal, and what I said made no sense. This should work:
> func unbridgedCast<T, U>(_ x: T, to: U.Type) -> U? {
>     guard type(of: x) is U.Type else { return nil }
>     return x as! U
> }
> if let x = unbridgedCast(x, to: String.self) { … }

Hmm, this one actually does seem to work. I had expected that type(of:) would be bridged as well. Thanks; this is definitely better than the Mirror workaround, at least.


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

More information about the swift-evolution mailing list