【发布时间】:2017-11-20 12:47:37
【问题描述】:
如果我有这个枚举:
enum TestEnum {
case typeA
case typeB(Int)
}
还有这个数组:let testArray = [TestEnum.typeB(1), .typeA, .typeB(3)]
有没有比以下更丑的方法来查找该数组中是否包含项目:
if testArray.contains(where: {if case .typeA = $0 { return true }; return false}) {
print("contained")
} else {
print("not found")
}
【问题讨论】: