Create multi-dimensional arrays!

Creating an empty array that holds strings or integers is as simple as writing

But what if you wanted to create an array where each item is an array of strings- an array of arrays?

This is called a multi-dimensional array and if you were to write this on a piece of paper it would appear as a grid rather then a line.

In swift, creating a multi-dimensional array is as easy as adding an extra set of square brackets around the array.

LOOK-OUT!

Arrays are value types! so if you add an array to another array then try and change it. Only one of the arrays will change.

The following code demonstrates the use of multi-dimensional arrays

 

Chessboard example