Why is this array out of index?

前端 未结 2 909
萌比男神i
萌比男神i 2021-01-27 17:02

I am trying to sort elements into a two dimensional array I built this way, but when the code gets to the 2D array I get an error: \"array out of index\".

var ca         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-27 17:39

    This worked in the end

    for x in categories{
                    for y in array{
                        if x == String(stringInterpolationSegment: y.categoryName){
                            var tempArray: [ProductCatalogue] = [y]
                        categoryTempArray.append(tempArray)
                            j++
                        }
                    }
                    i++
                }
    

    then i can use array like this categoryTempArray[i][j]

提交回复
热议问题