Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Last active February 20, 2021 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stevencurtis/758feb2c68cb7f8387c9597dba2ad850 to your computer and use it in GitHub Desktop.
Save stevencurtis/758feb2c68cb7f8387c9597dba2ad850 to your computer and use it in GitHub Desktop.
trailingSwipeActionsConfigurationProvider
private func createLayout() -> UICollectionViewLayout {
var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
config.trailingSwipeActionsConfigurationProvider = { indexPath in
guard let item = self.dataSource.itemIdentifier(for: indexPath) else {return nil}
return 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)
}
)]
)
}
return UICollectionViewCompositionalLayout.list(using: config)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment