Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2darray
class Array2D<T> {
let columns: Int
let rows: Int
var array: Array<T?> // private
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 {
array[row*columns + column] = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.