[swift-users] ?? operator question
zh ao
owenzx at gmail.com
Mon Apr 18 20:15:05 CDT 2016
I don't think NSNumber is OK here. As t1 is a struct not a literal value.
If NSNumber is OK. I think the compiler is too smart than it should be.
Also, you should aware that right side of let y works in print(), but does
not work in let, which is not consistent somehow.
Owen
On Mon, Apr 18, 2016 at 9:49 PM, Erica Sadun <erica at ericasadun.com> wrote:
>
> On Apr 18, 2016, at 7:23 AM, zh ao via swift-users <swift-users at swift.org>
> wrote:
>
> I do think there is something wrong here.
>
> // Xcode 7.3.1, Swift 2.2
>
> let t1: Int? = 2 // struct Int?
> let y = t1 ?? "abcdf" // error
> let x = t1 ?? NSFont(name: "", size: 0) // x: NSObject?
>
> for x, how could it be NSObject?, as t1 is a struct?
>
> zhaoxin
>
>
> My guess would be NSNumber.
>
> Strings can bridge to NSString (struct to class), enums of ErrorType to
> NSError (enum to class), etc.
>
> -- E
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160419/67ee6fcf/attachment.html>
More information about the swift-users
mailing list