Skip to content

Instantly share code, notes, and snippets.

public struct IfLet<T: OptionalType>: Content {
let data: T
let builder: (T.Wrapped) -> Content
public init(_ data: T, @ContentBuilder _ builder: @escaping (T.Wrapped) -> Content) {
self.data = data
self.builder = builder
}
public var contents: [Content]? {
public struct Map<Data: Collection>: Content {
var data: Data
var mapClosure: (Data.Element) -> Content
public init(_ data: Data, @ContentBuilder _ mapClosure: @escaping (Data.Element) -> Content) {
self.data = data
self.builder = builder
}
public var contents: [Content]? {
return data.map { mapClosure($0) }
public class DataSource: NSObject {
public var sections = [Section]()
}
extension DataSource: UITableViewDataSource {
public func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
lazy var dataSource = DataSource {
Section {
LabelCell(HeaderAdapter(label: "Example"))
Spacer(32)
}
model.items.ui.map { item in
Section {
Spacer()
override func reloadData() {
super.reloadData()
//...
let section = RandomSectionDescriptor().reloadSection { cells in
let titleItem = TitleDescriptor(adapter: TeamTitleAdapter(team: team))
cells.append(titleItem)
team.members.forEach { member in
import Foundation
import Collor
import CollorAPI
final class SampleCollectionData: CollorAPI.CollectionData {
override func reloadData() {
super.reloadData()
addSection().horizontalInset(.big).reloadSection { builder in
let block = builder.startDecorationBlock(type: .whiteBordered)
addSection().reloadSection { builder in
builder.journeyTimeline { timelineBuilder in
timelineBuilder.departure(...)
timelineBuilder.add(verticalSpace: ...)
timelineBuilder.info(descriptor: ...)
timelineBuilder.segmentArrival(..)
timelineBuilder.segmentDeparture(...)
timelineBuilder.info(descriptor: ...)
timelineBuilder.arrival(...)
override open func prepare() {
super.prepare()
//...
let decorationBlocks = collectionViewData.sections
.compactMap { $0 as? SectionDescriptor }
.flatMap { $0.decorationBlocks }
// ...
// after computing vertical spaces
decorationBlocks.forEach { decorationBlock in
public func startDecorationBlock(type: DecorationBlockType) -> DecorationBlock {
let startindex = cells.indices.last.flatMap { $0 + 1 } ?? 0 // start the decorationView after the last cell
let decorationBlock = DecorationBlock(type: type, startItemIndex: startindex, sectionDescriptor: sectionDescriptor)
return decorationBlock
}
public func endDecorationBlock(_ block: DecorationBlock?) {
guard let block = block else {
return
}
public final class DecorationBlock {
public let type: DecorationBlockType
unowned var sectionDescriptor: CollectionSectionDescribable
var startItemIndex: Int
var endItemIndex: Int
var firstIndexPath: IndexPath? {
guard let sectionIndex = sectionDescriptor.index else {