Skip to content

Instantly share code, notes, and snippets.

@icanswiftabit
Created November 16, 2017 09:55
Show Gist options
  • Save icanswiftabit/a8d46bd29c492c36b3fa530235ba7ea6 to your computer and use it in GitHub Desktop.
Save icanswiftabit/a8d46bd29c492c36b3fa530235ba7ea6 to your computer and use it in GitHub Desktop.
collectionView.pasteConfiguration = UIPasteConfiguration(forAccepting: UIImage.self)
...
override func paste(itemProviders: [NSItemProvider]) {
for provider in itemProviders {
provider.loadObject(ofClass: UIImage.self, completionHandler: { item, error in
guard error == nil else {
return
}
DispatchQueue.main.async {
self.viewModel.cats.append(Cat(name: "New cat", image: item as! UIImage))
self.collectionView.reloadData()
self.collectionView.reloadItems(at: self.collectionView.indexPathsForVisibleItems)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment