New Swift enthusiast here! I'm following Rey Wenderlich's Candy Crush tutorial and get an error when multiplying two Int
values. I know Swift is strictly typed so would be the reason? Am I not allowed to do this in Swift? Note the error
comments where I'm having trouble. Any help in the right direction is greatly appreciated!
class Array2D<T> {
let columns: Int
let rows: Int
let array: Array<T>
init(columns: Int, rows: Int) {
self.columns = columns
self.rows = rows
array = Array<T?>(count: rows*columns, repeatedValue: nil) // ERROR: could not find an overload for '*' that accepts the supplied arguments
}
subscript(column: Int, row: Int) -> T? {
get {
return array[row*columns + column]
}
set {
array[row*columns + column] = newValue // ERROR: could not find an overload for '*' that accepts the supplied arguments
}
}
}