Hello everyone.

I am currently implementing and in a UITextView.

In the UIDropInteractionDelegate canHande session: method , I accept both Images and Text as the following:

func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
    return session.hasItemsConforming(toTypeIdentifiers: [kUTTypeImage as String, kUTTypeText as String])

But with this I have noticed a problem: If I’m dropping an image from the , it accepts the image as expected but it also inserts the image URL string.

Is there any way to accept only one type at a ?

func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
    session.loadObjects(ofClass: UIImage.self) { (imageItems) in
        // image dropped

    session.loadObjects(ofClass: NSString.self) { (stringItems) in
        // text dropped

Source link


Please enter your comment!
Please enter your name here