Skip to content

Instantly share code, notes, and snippets.

@gwennguihal
Last active February 27, 2019 08:11
Show Gist options
  • Save gwennguihal/82abeae3fe0354437d924827d82860c9 to your computer and use it in GitHub Desktop.
Save gwennguihal/82abeae3fe0354437d924827d82860c9 to your computer and use it in GitHub Desktop.
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
}
// error if empty section
guard let lastIndex = cells.indices.last else {
fatalError("End block in a no empty section")
}
// check if startItemIndex does exist
guard cells.indices.contains(block.startItemIndex) else {
fatalError("Add a cell after startDecorationBlock(:) and before calling endDecorationBlock()")
}
block.endItemIndex = lastIndex
decorationBlocks.append(block)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment