Multidimensional subscripts

While the most common subscripts are the ones that take a single parameter, subscripts are not limited to single parameters. They can take any number of input parameters, and these parameters can be of any type.

Let's see how we could use a multidimensional subscript to implement a Tic-Tac-Toe board. A Tic-Tac-Toe board looks similar to this:

Multidimensional subscripts

The board can be represented by a two-dimensional array where each dimension has three elements. Each player will then take a turn placing his/her pieces (typically, X or O) within the board until one player has three pieces in a row or the board is full.

Let's see how we could implement ...

Get Mastering Swift 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.