[swift-evolution] Pitch: really_is and really_as operators

Xiaodi Wu xiaodi.wu at gmail.com
Wed Aug 24 21:47:28 CDT 2016


Works on Linux :)

On Wed, Aug 24, 2016 at 9:44 PM, Charles Srstka <cocoadev at charlessoft.com>
wrote:

> On Aug 24, 2016, at 7:42 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
>
> import Foundation
>
> let foo: Any = "Hello"
> type(of: foo) == String.self // true
> type(of: foo) == NSString.self // false
>
> let bar: Any = "Hello" as NSString
> type(of: bar) == String.self // false
> type(of: bar) == NSString.self // true
>
> Why not this?
>
>
> Because if you actually try that, it doesn’t work. type(of: bar) ==
> NSString.self actually returns false, not true, because the actual instance
> belongs to a private subclass of NSString, not NSString itself. type(of:
> bar) == NSClassFromString(“__NSCFString”) works, but that doesn’t really
> help us.
>
> Charles
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160824/9fb469f7/attachment.html>


More information about the swift-evolution mailing list