ra1028 / Former

Former is a fully customizable Swift library for easy creating UITableView based form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove crash

ilyatar opened this issue · 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
}`

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
}

`

Thank for reporting

Looking into this