[swift-evolution] Pitch: really_is and really_as operators
Charles Srstka
cocoadev at charlessoft.com
Wed Aug 24 21:44:44 CDT 2016
> 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/427314a1/attachment.html>
More information about the swift-evolution
mailing list