Question: In XCode, I'm writing a program in which data from a 2D String array is loaded into a 140 row by 5 column table. With this sample, if my array were {{a,b,c}{d,e,f}}, I want a table like

```
a  b  c
d  e  f

```

but I keep getting what a, d as the first 2 elements of my table going right on the first row. My code is:

```
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> GridViewCell {
    if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath as IndexPath) as? GridViewCell{

        var i = 0

        while (i < 5){
        cell.textLabel?.text = wholeArray[indexPath.row][i]

        cell.backgroundColor = UIColor.gray
        return cell
        }

    }
    else {
        DLog("ERROR")
        return GridViewCell()
    }
}

```

If there were an indexPath.column, I'd have tried that but there isn't. How might I get this to do what I need? This is a string array; I tried flatten() and it didn't work.

Answer: 
Instead of row, use item with some simple arithmetic:

```
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> GridViewCell {    
    if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath as IndexPath) as? GridViewCell, let columns = wholeArray.first?.count {
        let item = CGFloat(indexPath.item)

        let row = floor(item / CGFloat(columns))
        let column = item.truncatingRemainder(dividingBy: CGFloat(columns))

        cell.textLabel?.text = wholeArray[Int(row)][Int(column)]

        return cell
    } // no need to explicitly say else

    print("error")
    return GridViewCell()

```

}
var column = position % MAX\_ROWS  

var row = position / MAX\_COLUMNS

This should brake your position (index) down and give you the column and row you can used to index into your 2d array to allow for the result your looking for. 

Your basic problem is that the grid is treated like a linear list of cells and you just need some simple math to convert to a 2d grid.