Section

public struct Section

Represents a section of list UI, containing header node, footer node and collection of cell nodes. This works as an intermediary for DifferenceKit.

Example for simple section.

Section(
    id: 0,
    header: Label("Header"),
    footer: Label("Footer"),
    cells: {
        Label("Cell 0")
            .identified(by: \.text)

        Label("Cell 1")
            .identified(by: \.text)

        Label("Cell 2")
            .identified(by: \.text)
    }
)
  • id

    A type-erased identifier that can be used to uniquely identify the section.

    Declaration

    Swift

    public var id: AnyHashable
  • A node representing header view.

    Declaration

    Swift

    public var header: ViewNode?
  • A collection of nodes representing cells.

    Declaration

    Swift

    public var cells: [CellNode]
  • A node representing footer view.

    Declaration

    Swift

    public var footer: ViewNode?
  • Create a section wrapping id, header node, footer node and cell nodes.

    Declaration

    Swift

    @inlinable
    public init<I, C>(id: I, header: ViewNode? = nil, cells: C, footer: ViewNode? = nil) where I : Hashable, C : Collection, C.Element == CellNode

    Parameters

    id

    An identifier to be wrapped.

    header

    A node for header view.

    cells

    A collection of nodes for cells.

    footer

    A node for footer view.

  • Create a section wrapping id, header node, footer node and cell nodes.

    Note

    The nil contained in the collection of cell nodes is removed.

    Declaration

    Swift

    @inlinable
    public init<I, C>(id: I, header: ViewNode? = nil, cells: C, footer: ViewNode? = nil) where I : Hashable, C : Collection, C.Element == CellNode?

    Parameters

    id

    An identifier to be wrapped.

    header

    A node for header view.

    cells

    A collection of nodes for cells that can be contains nil.

    footer

    A node for footer view.

  • Create a section wrapping id, header node, footer node.

    Declaration

    Swift

    @inlinable
    public init<I>(id: I, header: ViewNode? = nil, footer: ViewNode? = nil) where I : Hashable

    Parameters

    id

    An identifier to be wrapped.

    header

    A node for header view.

    footer

    A node for footer view.

  • Build an array of section.

    Declaration

    Swift

    public func buildSections() -> [Section]
  • An identifier value for difference calculation.

    Declaration

    Swift

    @inlinable
    public var differenceIdentifier: AnyHashable { get }
  • The collection of element in the section.

    Declaration

    Swift

    @inlinable
    public var elements: [CellNode] { get }
  • Indicate whether the content of self is equals to the content of the given source value.

    Declaration

    Swift

    @inlinable
    public func isContentEqual(to source: Section) -> Bool
  • Creates a new section reproducing the given source section with replacing the elements.

    Declaration

    Swift

    @inlinable
    public init<C>(source: Section, elements cells: C) where C : Collection, C.Element == CellNode