Skip to content

Instantly share code, notes, and snippets.

@paul1893
Last active January 2, 2018 13:15
Show Gist options
  • Save paul1893/7b3511b82a66644044fea7f19d5bfc38 to your computer and use it in GitHub Desktop.
Save paul1893/7b3511b82a66644044fea7f19d5bfc38 to your computer and use it in GitHub Desktop.
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
// 1) Première possibilité
let progress = session.loadObjects(ofClass: UIImage.self) { imageItems in
let images = imageItems as! [UIImage]
self.selectedImageView.image = images.first
}
// 2) Seconde possibilité
for item in session.items {
item.itemProvider.loadObject(ofClass: UIImage.self) { (object, error) in
if object != nil {
// Je suis sur un background thread c’est donc ma responsabilité de revenir au main thread
DispatchQueue.main.async {
self.imageView.image = (object as! UIImage)
}
} else {
// Handle the error
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment