Separating multiple if conditions with commas in Swift

后端 未结 6 1529
轮回少年
轮回少年 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:09

    https://docs.swift.org/swift-book/ReferenceManual/Statements.html#grammar_condition-list

    The Swift grammar says that the if statement condition-list can be composed by multiple condition separated by commas ,

    A simple condition can be a boolean expression, a optional-binding-condition or other things:

    So, using the comma to separate multiple expressions is perfectly fine.

提交回复
热议问题