0Pricing
Swift Academy · Lesson

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

  1. Creating and Mutating Arrays
  2. Sorting, Searching and Slicing
  3. Map, Filter and Reduce on Arrays
  4. 2D Arrays and Nested Collections
← Back to Swift Academy