Separating multiple if conditions with commas in Swift

后端 未结 6 1533
轮回少年
轮回少年 2020-11-30 13:56

We already know multiple optional bindings can be used in a single if/guard statement by separating them with commas, but not with && e.g.



        
6条回答
  •  再見小時候
    2020-11-30 14:02

    In Swift 3, the where keyword in condition clauses were replaced by a comma instead.

    So a statement like if 1 == 1, 2 == 2 {} is saying "if 1 equals 1 where 2 equals 2..."

    It's probably easiest to read a conditional statement with an && instead of a ,, but the results are the same.

    You can read more about the details of the change in Swift 3 in the Swift Evolution proposal: https://github.com/apple/swift-evolution/blob/master/proposals/0099-conditionclauses.md

提交回复
热议问题