Error rápido: 'Secuencia' requiere que los tipos 'T' y 'ArraySlice <T>' sean equivalentes
Estoy tratando de actualizar una biblioteca matemática para que sea compatible con Swift 3, pero me encuentro con un error:
'Sequence' requires the types 'T' and 'ArraySlice<T>' be equivalent
La documentación de Apple sobre Sequence recomienda que el método makeIterator () devuelva un iterador, lo que hace. Y parece que el iterador está devolviendo un elemento en elgrid
variable, que es de variableT
. No estoy muy seguro de lo que me estoy perdiendo aquí. Cualquier consejo sería útil.
public struct Matrix<T> where T: FloatingPoint, T: ExpressibleByFloatLiteral {
public typealias Element = T
let rows: Int
let columns: Int
var grid: [Element]
public init(rows: Int, columns: Int, repeatedValue: Element) {
self.rows = rows
self.columns = columns
self.grid = [Element](repeating: repeatedValue, count: rows * columns)
}
...
}
extension Matrix: Sequence { // <-- getting error here
public func makeIterator() -> AnyIterator<ArraySlice<Element>> {
let endIndex = rows * columns
var nextRowStartIndex = 0
return AnyIterator {
if nextRowStartIndex == endIndex {
return nil
}
let currentRowStartIndex = nextRowStartIndex
nextRowStartIndex += self.columns
return self.grid[currentRowStartIndex..<nextRowStartIndex]
}
}
}