[swift-evolution] Pitch: really_is and really_as operators

Adrian Zubarev adrian.zubarev at devandartist.com
Thu Aug 25 14:40:32 CDT 2016


Is that what you guys wanted to achieve?

@inline(never)
func opaqueCast<T,U>(_ x: T, _: U.Type) -> Bool {
    return x is U
}

let foo: Any = "Foo"
let bar: Any = NSString(string: "Bar")

let fooIsString = foo is String               // true
opaqueCast(type(of: foo), String.Type.self)   // true

let fooIsNSString = foo is NSString           // true
opaqueCast(type(of: foo), NSString.Type.self) // false

let barIsString = bar is String               // true
opaqueCast(type(of: bar), String.Type.self)   // false

let barIsNSString = bar is NSString           // true
opaqueCast(type(of: bar), NSString.Type.self) // true
Joe Groff showed me this little trick when is cast was bugged in some Xcode beta for Swift 1.2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160825/fae16763/attachment.html>


More information about the swift-evolution mailing list