Former icon indicating copy to clipboard operation
Former copied to clipboard

Remove crash

Open ilyatar opened this issue 6 years ago • 3 comments

Crash If remove all rows from section: section.remove(rowFormers: section.rowFormers) because it method is incorrect:

`public func remove(rowFormers: [RowFormer]) -> Self {

    var removedCount = 0
    for (index, rowFormer) in self.rowFormers.enumerated() {
        if rowFormers.contains(where: { $0 === rowFormer }) {
            remove(atIndex: index)  //REMOVE INSIDE CYCLE, COUNT OF ELEMENTS CHANGED EVERY ITERATION
            removedCount += 1
            if removedCount >= rowFormers.count {
                return self
            }
        }
    }
    return self
}`

ilyatar avatar Mar 30 '18 09:03 ilyatar

It's right:

` public func remove(rowFormers: [RowFormer]) -> Self {

    for rowFormer in rowFormers {
        if let index = self.rowFormers.index(where: {$0 === rowFormer}) {
            remove(atIndex: index)
        }
    }
    
    return self
}

`

ilyatar avatar Mar 30 '18 19:03 ilyatar

Thank for reporting

cuongnv avatar Feb 21 '19 15:02 cuongnv

Looking into this

ZacharyKhan avatar Jun 19 '19 18:06 ZacharyKhan