2D Arrays and Nested Collections
Working with arrays of arrays, flattening with flatMap and compactMap.
Welcome
2D arrays and nested collections model grids, tables, graphs, and hierarchical data. Swift handles them naturally — just nest array types.
Declaring a 2D Array
```swift
var grid: [[Int]] = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(grid[1][2]) // 6
```
All lessons in this course
- Creating and Mutating Arrays
- Sorting, Searching and Slicing
- Map, Filter and Reduce on Arrays
- 2D Arrays and Nested Collections