[swift-evolution] ternary operator ?: suggestion

J. Cheyo Jimenez cheyo at masters3d.com
Fri Dec 11 19:44:55 CST 2015


+1 I personally really like the if then expression. I think is cleaner and
this way we can have if else expressions with curly braces too. Introducing
the then keyword also could allow for switch expressions.

let result =  switch (yourColor) {
               case .Red   then 1
               case .Green then 2
               case .Blue  then 3
          }


On Fri, Dec 11, 2015 at 5:31 PM, Al Skipp via swift-evolution <
swift-evolution at swift.org> wrote:

> How about:
>
> let v = if condition then “A" else “B"
>
> No mysterious symbols or braces, or multiline monstrosity.
>
> > On 12 Dec 2015, at 01:18, Andrey Tarantsov via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > Strong -1; this turns a quick one-liner into a multiline monstrosity.
> When massaging coordinates and layouts in iOS apps, ?: is often helpful to
> handle corner cases inline.
> >
> > A.
> >
> > _______________________________________________
> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151211/b7a00eeb/attachment.html>


More information about the swift-evolution mailing list