SectionUI Skill
SectionUI (formerly SectionKit) is a powerful, data-driven framework for building complex UICollectionView layouts in Swift. It abstracts away the complexity of UICollectionViewDataSource and UICollectionViewDelegate, allowing you to focus on composable Sections and Cells.
Core Components
- SKCManager: The central coordinator that manages sections and binds them to the
UICollectionView.
- SKCollectionView: A subclass of
UICollectionView optimized for use with SectionUI.
- SKCSingleTypeSection: A generic section type for displaying a list of identical cells (homogenous data).
- SKLoadViewProtocol & SKConfigurableView: Protocols that Cells must conform to for automatic registration and configuration.
Reference Documentation
Core Components
- Cell Creation & Configuration - SKLoadViewProtocol, SKConfigurableView, Auto Layout integration, adaptive cells
- Section Management - SKCSingleTypeSection basics, event handling, headers/footers, styling
- Manager & CollectionView - SKCManager, SKCollectionView, SKCollectionViewController
Advanced Features
- Advanced Sections - SKCHostingSection (SwiftUI), SKCAnyViewCell, SKCSectionViewCell (nested sections)
- Reactive Programming - SKPublished, data subscription, prefetch publishers, selection publishers
- Performance Optimization - SKHighPerformanceStore (size caching), prefetching, display times tracking, safe size providers
- Selection Management - SKSelectionProtocol, SKSelectionWrapper, SKCDragSelector (multi-select)
- Pin Functionality - Sticky headers/footers/cells, distance tracking, custom animations
- Scroll Management - SKScrollViewDelegateHandler, SKCDisplayTracker, scroll control
- Layout Plugins - Vertical/horizontal alignment, SKWaterfallLayout, custom attribute plugins
- Decorations - Background decorations, custom decoration views
- Page View Controller - SKPageManager, SKPageViewController, nested scrolling
Examples
Templates
- Adaptive Cell - Template for a cell with self-sizing capabilities.
- Mixed Cells Section - Template for a section managing multiple cell types.
- Section Cell - Template for a standard configurable cell.
Quick Start Guide
1. Basic Setup
Use SKCollectionViewController or SKCollectionView to get started quickly.
class MyViewController: SKCollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Setup sections here
manager.reload(mySection)
}
}
2. Creating a Cell
Cells must conform to SKLoadViewProtocol and SKConfigurableView:
class MyCell: UICollectionViewCell, SKLoadViewProtocol, SKConfigurableView {
struct Model {
let title: String
}
static func preferredSize(limit size: CGSize, model: Model?) -> CGSize {
return CGSize(width: size.width, height: 50)
}
func config(_ model: Model) {
label.text = model.title
}
private lazy var label = UILabel()
}
3. Creating a Section
The most common pattern is using wrapperToSingleTypeSection on your Cell type.
let section = MyCell.wrapperToSingleTypeSection()
.onCellAction(.selected) { context in
print("Selected: \(context.model)")
}
section.config(models: [Model1, Model2, ...])
manager.reload(section)
4. Reactive Updates
SectionUI works seamlessly with Combine:
@SKPublished var items: [Model] = []
$items.bind { [weak self] newItems in
self?.section.config(models: newItems)
}.store(in: &cancellables)
// Or subscribe directly
section.subscribe(models: $items.eraseToAnyPublisher())
Common Usage Patterns
Performance Optimization
section
.setHighPerformance(.init())
.highPerformanceID { $0.model.id }
Sticky Headers
section.pinHeader { options in
options.padding = 16
}
Selection Management
let selectableItems = items.map { SKSelectionWrapper(value: $0) }
section.config(models: selectableItems)
Waterfall Layout
let layout = SKWaterfallLayout()
.columnWidth(equalParts: 2)
.heightCalculationMode(.aspectRatio)
SwiftUI Integration
@available(iOS 16.0, *)
let section = SKCHostingSection(
cell: MySwiftUIView.self,
models: viewModels
)
Best Practices
- Prefer
SKCManager: Always use SKCManager to manipulate sections (reload, insert, delete).
- Fluent Configuration: Use the chainable generic methods on
SKCSingleTypeSection (onCellAction, setSectionSeparators, etc.) instead of subclassing whenever possible.
- Decomposition: Break complex lists into multiple small Sections.
- Use Reactive Binding: Leverage Combine and
SKPublished for automatic UI updates.
- Cache Sizes: Use
SKHighPerformanceStore for complex Auto Layout calculations.
- Weak References: Always use
[weak self] in closures to avoid retain cycles.
- Naming Convention: When declaring a
UICollectionView variable, use sectionView as the variable name instead of collectionView.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: sectionui3description: Master skill for SectionUI (SectionKit), a powerful data-driven framework for building complex UICollectionView layouts in Swift. Use when working with UICollectionView, building list interfaces, implementing reactive data binding with Combine, optimizing collection view performance, managing selection state, implementing sticky headers/footers, creating waterfall layouts, integrating SwiftUI views, handling scroll events, or implementing page-based navigation. Covers cells, sections, managers, layout plugins, decorations, performance optimization, reactive programming, selection management, scroll observation, and page view controllers. Use when this capability is needed.4---56# SectionUI Skill78`SectionUI` (formerly SectionKit) is a powerful, data-driven framework for building complex `UICollectionView` layouts in Swift. It abstracts away the complexity of `UICollectionViewDataSource` and `UICollectionViewDelegate`, allowing you to focus on composable **Sections** and **Cells**.910## Core Components11121. **SKCManager**: The central coordinator that manages sections and binds them to the `UICollectionView`.132. **SKCollectionView**: A subclass of `UICollectionView` optimized for use with `SectionUI`.143. **SKCSingleTypeSection**: A generic section type for displaying a list of identical cells (homogenous data).154. **SKLoadViewProtocol & SKConfigurableView**: Protocols that Cells must conform to for automatic registration and configuration.1617## Reference Documentation1819### Core Components20- **[Cell Creation & Configuration](references/cell.md)** - SKLoadViewProtocol, SKConfigurableView, Auto Layout integration, adaptive cells21- **[Section Management](references/section.md)** - SKCSingleTypeSection basics, event handling, headers/footers, styling22- **[Manager & CollectionView](references/manager.md)** - SKCManager, SKCollectionView, SKCollectionViewController2324### Advanced Features25- **[Advanced Sections](references/advanced-sections.md)** - SKCHostingSection (SwiftUI), SKCAnyViewCell, SKCSectionViewCell (nested sections)26- **[Reactive Programming](references/reactive.md)** - SKPublished, data subscription, prefetch publishers, selection publishers27- **[Performance Optimization](references/performance.md)** - SKHighPerformanceStore (size caching), prefetching, display times tracking, safe size providers28- **[Selection Management](references/selection.md)** - SKSelectionProtocol, SKSelectionWrapper, SKCDragSelector (multi-select)29- **[Pin Functionality](references/pin.md)** - Sticky headers/footers/cells, distance tracking, custom animations30- **[Scroll Management](references/scroll.md)** - SKScrollViewDelegateHandler, SKCDisplayTracker, scroll control31- **[Layout Plugins](references/layout-plugins.md)** - Vertical/horizontal alignment, SKWaterfallLayout, custom attribute plugins32- **[Decorations](references/decorations.md)** - Background decorations, custom decoration views33- **[Page View Controller](references/page.md)** - SKPageManager, SKPageViewController, nested scrolling3435### Examples36- [Basic List](examples/BasicListViewController.swift)37- [Decorations](examples/DecorationExampleViewController.swift)3839### Templates40- [Adaptive Cell](examples/AdaptiveCellTemplate.swift) - Template for a cell with self-sizing capabilities.41- [Mixed Cells Section](examples/MixedCellsSectionTemplate.swift) - Template for a section managing multiple cell types.42- [Section Cell](examples/SectionCellTemplate.swift) - Template for a standard configurable cell.4344## Quick Start Guide4546### 1. Basic Setup47Use `SKCollectionViewController` or `SKCollectionView` to get started quickly.4849```swift50class MyViewController: SKCollectionViewController {51 override func viewDidLoad() {52 super.viewDidLoad()53 // Setup sections here54 manager.reload(mySection)55 }56}57```5859### 2. Creating a Cell60Cells must conform to `SKLoadViewProtocol` and `SKConfigurableView`:6162```swift63class MyCell: UICollectionViewCell, SKLoadViewProtocol, SKConfigurableView {64 struct Model {65 let title: String66 }6768 static func preferredSize(limit size: CGSize, model: Model?) -> CGSize {69 return CGSize(width: size.width, height: 50)70 }7172 func config(_ model: Model) {73 label.text = model.title74 }75 76 private lazy var label = UILabel()77}78```7980### 3. Creating a Section81The most common pattern is using `wrapperToSingleTypeSection` on your Cell type.8283```swift84let section = MyCell.wrapperToSingleTypeSection()85 .onCellAction(.selected) { context in86 print("Selected: \(context.model)")87 }8889section.config(models: [Model1, Model2, ...])90manager.reload(section)91```9293### 4. Reactive Updates94`SectionUI` works seamlessly with Combine:9596```swift97@SKPublished var items: [Model] = []9899$items.bind { [weak self] newItems in100 self?.section.config(models: newItems)101}.store(in: &cancellables)102103// Or subscribe directly104section.subscribe(models: $items.eraseToAnyPublisher())105```106107## Common Usage Patterns108109### Performance Optimization110```swift111section112 .setHighPerformance(.init())113 .highPerformanceID { $0.model.id }114```115116### Sticky Headers117```swift118section.pinHeader { options in119 options.padding = 16120}121```122123### Selection Management124```swift125let selectableItems = items.map { SKSelectionWrapper(value: $0) }126section.config(models: selectableItems)127```128129### Waterfall Layout130```swift131let layout = SKWaterfallLayout()132 .columnWidth(equalParts: 2)133 .heightCalculationMode(.aspectRatio)134```135136### SwiftUI Integration137```swift138@available(iOS 16.0, *)139let section = SKCHostingSection(140 cell: MySwiftUIView.self,141 models: viewModels142)143```144145## Best Practices146- **Prefer `SKCManager`**: Always use `SKCManager` to manipulate sections (reload, insert, delete).147- **Fluent Configuration**: Use the chainable generic methods on `SKCSingleTypeSection` (`onCellAction`, `setSectionSeparators`, etc.) instead of subclassing whenever possible.148- **Decomposition**: Break complex lists into multiple small Sections.149- **Use Reactive Binding**: Leverage Combine and `SKPublished` for automatic UI updates.150- **Cache Sizes**: Use `SKHighPerformanceStore` for complex Auto Layout calculations.151- **Weak References**: Always use `[weak self]` in closures to avoid retain cycles.152- **Naming Convention**: When declaring a `UICollectionView` variable, use `sectionView` as the variable name instead of `collectionView`.153154---155> Converted and distributed by [TomeVault](https://tomevault.io/claim/linhay) — claim your Tome and manage your conversions.156<!-- tomevault:4.0:skill_md:2026-04-11 -->