Skip to content

Introduce data structure for sections #18

Description

@ishkawa

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)
        })
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions