ForEach - 打印项目和数值

ForEach - print both an item and numerical value

我怎样才能获得显示每个数组成员的 ForEach 结果,以及取决于列表计数的数值,每个项目递增

例子是 1“火鸡” 2“火腿” 3“梅奥”

struct EditorDirections: View {
    @State private var recipeDirections: [String] = ["Ham", "Turkey", "Mayo"]
   
    
    var body: some View {
        VStack{
            List{
                ForEach(recipeDirections, id: \.self){ recipe in
                    HStack{
                        Text()// show 1, 2, 3
                        Text(recipe)
                    }
                }
           }

尝试使用枚举

ForEach(Array(recipeDirections.enumerated()), id: \.offset){ (index,recipe) in

根据数组编号,索引将为 0,1,2。