Skip to content

Commit 01eb805

Browse files
authored
Merge pull request kodecocodes#158 from APesate/Array2DImprovement
Added preconditions to subscript to avoid unwanted changes or crashes.
2 parents 86b2fe3 + c77a748 commit 01eb805

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Array2D/Array2D.swift

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public struct Array2D<T> {
1919
return array[row*columns + column]
2020
}
2121
set {
22+
precondition(row < rows, "Row \(row) Index is out of range. Array<T>(columns: \(columns), rows:\(rows))")
23+
precondition(column < columns, "Column \(column) Index is out of range. Array<T>(columns: \(columns), rows:\(rows))")
24+
2225
array[row*columns + column] = newValue
2326
}
2427
}

0 commit comments

Comments
 (0)