Swifterswift: UITableView .indexPathForLastRow is wrong

Created on 6 Jan 2017  路  2Comments  路  Source: SwifterSwift/SwifterSwift

https://github.com/omaralbeik/SwifterSwift/blob/development/Source/Extensions/UI/UITableViewExtensions.swift#L16

current implementation is wrong:

    public var indexPathForLastRow: IndexPath? {
        guard numberOfRows > 0 else {
            return nil
        }
        return IndexPath(row: numberOfRows - 1, section: lastSection)
    }

it should be:

     return IndexPath(row: indexPathForLastRow(in: lastSection), section: lastSection)

Most helpful comment

@muescha True, however the code is a bit repetitive and didn't work because an optional IndexPath being passed to method instead of row

return IndexPath(row: indexPathForLastRow(in: lastSection), section: lastSection)

I refactored the code to:

public var indexPathForLastRow: IndexPath? {
    return indexPathForLastRow(inSection: lastSection)
}

Will change it in the next release, thank you!

All 2 comments

@muescha True, however the code is a bit repetitive and didn't work because an optional IndexPath being passed to method instead of row

return IndexPath(row: indexPathForLastRow(in: lastSection), section: lastSection)

I refactored the code to:

public var indexPathForLastRow: IndexPath? {
    return indexPathForLastRow(inSection: lastSection)
}

Will change it in the next release, thank you!

yes - that is much shorter :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omaralbeik picture omaralbeik  路  3Comments

g001613001 picture g001613001  路  5Comments

marcocapano picture marcocapano  路  5Comments

bjimenezned picture bjimenezned  路  3Comments

pawurb picture pawurb  路  3Comments