我有一个枚举我想只为某些情况执行代码而在其他所有时间都不执行任何操作(非详尽)
这似乎对Swift来说过于冗长
if num == .One || num == .Two || num == .Three || num == .Four { //code }
这让我有一个默认情况,我想什么都不做,但仍然需要添加类似打印的东西
switch num { case .One,.Two. Three,.Four: //code default: print("do nothing but I still need to put something here") }
我想做这样的事情……它存在于Swift中吗?
if case .One,.Two,.Three,.Four == num { //code }
解决方法
if [.One,.Four].contains(num) {