Skip to content

Instantly share code, notes, and snippets.

@emarashliev
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save emarashliev/1f0e47d12a9e70edae80 to your computer and use it in GitHub Desktop.

Select an option

Save emarashliev/1f0e47d12a9e70edae80 to your computer and use it in GitHub Desktop.
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
}
}
}
var array2D = Array2D<String>(columns: 3, rows: 3)
array2D[1, 1] = "a"
array2D[1, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment