switch-枚举

在swift中,如果switch的枚举,可以不写default,因为系统知道有多少种情况,如果不是枚举,必须要写default

1 enum WBComposeToolBarButtonType:Int {
2     case picture // 图片
3     case mention // @
4     case trend   // #
5     case emotion // 表情
6     case add     // +
7 }
1 // 枚举值设置为Tag值,rawValue表示枚举的原始值(对应的数字)
2         button.tag = type.rawValue
1 // MARK: - 点击事件
2     @objc private func btnAction(btn:UIButton){
3         // 根据枚举原始值创建枚举
4         let type = WBComposeToolBarButtonType(rawValue: btn.tag)!
5     }
原文地址:https://www.cnblogs.com/panda1024/p/6188895.html