Tested with Swift 3.0 Xcode 8 beta 6 playground.
-- Adrian Zubarev Sent with Airmail Am 25. August 2016 um 23:15:24, Vladimir.S (sva...@gmail.com) schrieb: > let fooIsNSString = foo is NSString // true I don't understand. Why is so? On which version of Swift did you try this? IBM Swift Sandbox Swift Ver. 3.0 (Aug 23, 2016) Platform: Linux (x86_64) import Foundation let foo: Any = "Foo" let bar: Any = NSString(string: "Bar") let fooIsString = foo is String print(fooIsString) // true let fooIsNSString = foo is NSString print(fooIsNSString) // false! as expected On 25.08.2016 22:40, Adrian Zubarev via swift-evolution wrote: > 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. > > > > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution >
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution