Is there a way to write an `if case` statement as an expression?

后端 未结 3 634
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 17:13

Consider this code:

enum Type {
    case Foo(Int)
    case Bar(Int)

    var isBar: Bool {
        if case .Bar = self {
            return true
        } else {         


        
3条回答
  •  独厮守ぢ
    2021-02-01 17:26

    Are you looking for the ? operator ?

    documentation is here under the Ternary Conditional Operator title.

提交回复
热议问题