I\'m trying to write an extension for the Matrix
example from the book, slightly tweaked to be generic.
I\'m trying to write a method called getRow
I think you are being mislead by the Swift compiler (which is a bit flaky at the moment). The type for your range 0..self.columns
is Range
, which is not a Sequence
or Collection
, so I don't think it can be used via map
.
The implementation works for me:
extension Matrix {
func getRow(index: Int) -> T[] {
var row = T[]()
for col in 0..self.columns {
row.append(self[index, col])
}
return row
}
}