0
如何獲取for case let
模式匹配中迭代枚舉元素的索引?用於案例模式匹配的枚舉元素索引
我有一個枚舉:
enum EnumType {
case A(associatedValue: Int)
case B(associatedValue: String)
}
和陣列枚舉元素:
let arrayOfEnums: [EnumType] = [.A(1), B("A"), .A(2), B("B")]
在for
環,其中I遍歷僅A
元件,我想獲得當前迭代的元素的索引in arrayOfEnums
array:
for case let EnumType.A(associatedValue) in arrayOfEnums {
// operations here
}
我kn自己,我可以從Array.enumerated()
索引,但我不知道如何在for case
做到這一點。