Other answers work, but you can use the Swift, subscriptip, and optionsals generators to create a typically typed class of 2D arrays:
class Array2D<T> {
let columns: Int
let rows: Int
var array: Array<T?>
init(columns: Int, rows: Int) {
self.columns = columns
self.rows = rows
array = Array<T?>(count:rows * columns, repeatedValue: nil)
}
subscript(column: Int, row: Int) -> T? {
get {
return array[(row * columns) + column]
}
set(newValue) {
array[(row * columns) + column] = newValue
}
}
}
( struct, mutating.)
:
var boolArray = Array2D<Bool>(columns: 10, rows: 10)
boolArray[4, 5] = true
let foo = boolArray[4, 5]