Ad space (banner)
๐ŸŽObjective-C Lessons
Lesson 24 / 68

Two-dimensional arrays (tabular data)

This lesson covers two-dimensional arrays in Objective-C, with the aim of handling data in table form.

Putting arrays inside an array expresses a grid with rows and columns — a two-dimensional array. You reach into it as grid[row][column].

The sample code declares two rows by three columns as @[@[@1, @2, @3], @[@4, @5, @6]] and reaches a value with doubled brackets, as in grid[1][2]. Note for (NSArray *row in grid), which takes each row out whole.

A common early stumble is that a two-dimensional array here is just an NSArray inside an NSArray. It is a nest of objects, not the fixed-size memory block of C.

In professional work, this idea is applied to game boards with coordinates and to spreadsheet-like data.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Objective-C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)