[swift-users] The nil coalescing operator

Jordan Rose jordan_rose at apple.com
Tue Feb 23 11:09:29 CST 2016


That does seem like a bug, but one possibility is that 'result' has type 'AnyObject', and so you're getting an extra level of optional due to the subscript operator possibly not being there. Do you have a full, self-contained test case?

Jordan

> On Feb 22, 2016, at 15:17 , Valentin Radu via swift-users <swift-users at swift.org> wrote:
> 
> Hello all,
> 
> 
> I have a question re the nil coalescing operator. Shouldn’t 
> 
> print ("This machine's ip is \(result["ip"] ?? “unknown")”) 
> 
> return This machine's ip is 78.97.202.31 ? Since the value is always String, not String?.  However, it still surrounds the ip with Optional(). 
> 
> So I’m using, (result.0["ip"] ?? "nil").description but is long and dirty. Any thoughts? 
> 
> Cheers!
> – V
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160223/fc53ab20/attachment.html>


More information about the swift-users mailing list