Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created July 3, 2020 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/c36e00b482c157711084899e97b44bf0 to your computer and use it in GitHub Desktop.
Save stevencurtis/c36e00b482c157711084899e97b44bf0 to your computer and use it in GitHub Desktop.
cell registration
let registrationUICollectionViewListCell = UICollectionView.CellRegistration<UICollectionViewListCell, String> { (cell, indexPath, item) in
var content = cell.defaultContentConfiguration()
content.text = "\(item)"
cell.contentConfiguration = content
cell.trailingSwipeActionsConfiguration = UISwipeActionsConfiguration(
actions: [UIContextualAction(
style: .destructive,
title: "Delete",
handler: { [weak self] _, _, completion in
guard let self = self else {return}
self.snapshot.deleteItems([item])
self.dataSource.apply(self.snapshot, animatingDifferences: false)
completion(true)
}
)]
)
}
let registrationCustomListCell = UICollectionView.CellRegistration<BasicCollectionViewCell, String> { (cell, indexPath, item) in
cell.updateWithText(item)
(cell as UICollectionViewListCell).trailingSwipeActionsConfiguration = UISwipeActionsConfiguration(
actions: [UIContextualAction(
style: .destructive,
title: "Delete",
handler: { [weak self] _, _, completion in
guard let self = self else {return}
self.snapshot.deleteItems([item])
self.dataSource.apply(self.snapshot, animatingDifferences: false)
completion(true)
}
)]
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment