[swift-evolution] ternary operator ?: suggestion

J. Cheyo Jimenez cheyo at masters3d.com
Fri Dec 11 19:53:22 CST 2015


I meant if else statements. If we introduce the then keyword we could have
and if then expression that is separate from the if else statement.

On Fri, Dec 11, 2015 at 5:44 PM, J. Cheyo Jimenez <cheyo at masters3d.com>
wrote:

> +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/e6e866d0/attachment.html>


More information about the swift-evolution mailing list