DataSourceKit icon indicating copy to clipboard operation
DataSourceKit copied to clipboard

Introduce data structure for sections

Open ishkawa opened this issue 5 years ago • 1 comments

Currently, declarations of contents of UITableView are expressed by [CellDeclaration]. One idea to support sections is expressing sections by some type like [TableViewSectionDeclaration<CellDeclaration>].

struct TableViewSectionDeclaration<CellDeclaration> {
    let headerTitle: String?
    let footerTitle: String?
    let cellDeclarations: [CellDeclaration]
    
    init(
        headerTitle: String? = nil,
        footerTitle: String? = nil,
        declareCells: @escaping (@escaping (CellDeclaration) -> Void) -> Void) {
        ...
    }
}

With TableViewSectionDeclaration<CellDeclaration>, a conformer may look like:

class ViewController: SectionsDeclarator {
    enum CellDeclaration {
        case a, b
    }

    func declareSections(_ section: (TableViewSectionDeclaration<CellDeclaration>) -> Void) {
        section(TableViewSectionDeclaration(headerTitle: "A") { cell in
            cell(.a)
        })

        section(TableViewSectionDeclaration(headerTitle: "B") { cell in
            cell(.b)
            cell(.b)
            cell(.b)
        })
    }
}

ishkawa avatar Oct 14 '18 16:10 ishkawa

Hey, thanks for sharing your thoughts. This proposal would add support for PR #9 and PR #10 right ? Any updates on this ? We are currently maintaining a fork for both of these features to work.

dehlen avatar Nov 23 '18 13:11 dehlen