[swift-evolution] ternary operator ?: suggestion

Thorsten Seitz thorsten.seitz at web.de
Sun Dec 6 08:25:22 CST 2015


I’d prefer if-expressions to have the same form as if-statements, i.e.

let greeting = if let name = optionalName { "Hello, \(name),“ } else { “To Whom It May Concern:” }

-Thorsten


PS: As an aside this could also be written without an if-expression as follows:

let greeting = name.map(„Hello, \($0),“) ?? “To Whom It May Concern:”


With regards to the question about the required else part: 
> Am 06.12.2015 um 01:12 schrieb Alex Lew via swift-evolution <swift-evolution at swift.org>:
> 
> let greeting = “Hello, \(name),” if let name = optionalName else “To Whom It May Concern:”
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/eb3fc4ad/attachment.html>


More information about the swift-evolution mailing list