[swift-evolution] Pitch: really_is and really_as operators
Vladimir.S
svabox at gmail.com
Thu Aug 25 16:29:18 CDT 2016
I believe that due to SE-0072 my code(Swift Ver. 3.0 (Aug 23, 2016) on
Linux) is working right, no?
On 26.08.2016 0:18, Adrian Zubarev via swift-evolution wrote:
> 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 (svabox at gmail.com
> <mailto:svabox at 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 at swift.org
>> > https://lists.swift.org/mailman/listinfo/swift-evolution
>> >
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
More information about the swift-evolution
mailing list