Generated: 2026-01-19 Scope: Usage patterns & Best practices from demonstrations.
The Example/ directory serves as the living documentation for SectionKit. It demonstrates how to decompose complex UIs into isolated, reusable units using the protocol-oriented architecture of SectionKit and SectionUI.
- Section Initialization: Prefer
Cell.wrapperToSingleTypeSection(models)for concise instantiation. - Fluent Configuration: Use chaining for section setup:
section .setSectionStyle { $0.minimumLineSpacing = 10 } .cellSafeSize(.fraction(0.5), transforms: .height(asRatioOfWidth: 1)) .onCellAction(.selected) { context in ... }
- Wrapper Pattern: Bridge any
UIViewto a cell usingSKCWrapperCell<CustomView>. The view only needs to conform toSKConfigurableView. - Global Orchestration: Use
SKCManagerto manage multiple sections; usemanager.reload(sections)for full state updates.
- Model-Driven: Use
@SKPublishedin your model classes to broadcast state changes. - Cell Binding: Inside
config(_:), bind to model publishers and store incancellables. - Cleanup: Always call
cancellables.removeAll()at the start ofconfig(_:)to prevent duplicate bindings during cell reuse.
- Incremental Updates: Use
section.append(models)for pagination instead of reloading the entire manager. - Header/Footer: Dynamically update decorators via
section.setHeader(View.self, model: model)followed bysection.reload(). - Memory Safety: ALWAYS use
[weak self]in.onCellActionand reactive.bindclosures. Sections are often held by the Manager/VC, and Cells are reused; strong captures will cause leaks.
- Sizing: Implement
preferredSizeinSKLoadViewProtocolfor efficient layout calculations. Usestaticmethods to avoid instantiation overhead. - State Management: Keep business logic in the Section or ViewModel; keep the Cell focused strictly on rendering the provided Model.