ios - Why is this array out of index? -


i trying sort elements 2 dimensional array built way, when code gets 2d array error: "array out of index".

var categorytemparray: [[productcatalogue]] = []  func sortinout(){     var = 0     var j = 0         x in categories{             y in array{                 if x == string(stringinterpolationsegment: y.categoryname){                 categorytemparray[i].append(y)                 //categorytemparray[i][j] = y tried                     j++                 }             }             i++         }} 

you should initialize [i]th element before appending [j]th element it.

you call append() function on item not exist, since no item exists in categorytemparray array, index out of bound.


Comments