加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift可以在switch case语句中有多个参数吗?

发布时间:2020-12-14 04:50:59 所属栏目:百科 来源:网络整理
导读:如果我在枚举中设置了我的案例,我可以在switch语句中调用多个这样的案例吗?又名case .a,.b:return true enum myLetters { case a case b case c var myCondition: Bool { switch self { case .a,.b: return true case .c: return false default: return fa
如果我在枚举中设置了我的案例,我可以在switch语句中调用多个这样的案例吗?又名case .a,.b:return true

enum myLetters {
  case a
  case b
  case c

    var myCondition: Bool {
      switch self {
      case .a,.b: return true
      case .c: return false
      default: return false
    }
  }
}

解决方法

是的,请看一下Swift documentation on switch声明.

为了达到你想要的效果,你需要检查myLetters的当前值:

var myCondition: Bool {
    switch self {
    case .a,.b: return true
    case .c: return false
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读