[swift-users] ?? operator question

tuuranton at tutanota.de tuuranton at tutanota.de
Mon Apr 18 04:51:49 CDT 2016


Why does this compile?
let t1: Int? = 2print(t1 ?? "asdf")
The type of ?? is this:
@warn_unused_resultpublic func ??<T>(optional: T?, @autoclosure defaultValue: 
() throws -> T) rethrows -> T
The type syas that T must be the same type throughout. But above I could 
successfully use Int? and then String. Why?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160418/bb6c6ae5/attachment.html>


More information about the swift-users mailing list