I have drag-and-drop functionality in the macOS app built with SwiftUI.
Since macOS 15 there is an issue with it, because as I found out, the completion block of loadObject
method on NSItemProvider
is not called until dropExited
delegate method is called (see simplified code example below).
It causes very strange behavior in my app, for one of the most important features, and I am looking for a way to fix it as soon as possible.
Is anyone seeing the same issue?
I saw there was a bug with drag and drop on iOS 18, which seems to be fixed in 18.1. Anyone from Apple can say anything about this change in behaviour?
@Observable // Because it is injected via environment.
final class DragAndDropDelegate<T: Codable>: DropDelegate {
func dropEntered(info: DropInfo) {
// Is called as expected.
guard
let itemProvider = info.itemProviders(for: [UTType.data]).first
else { return }
itemProvider.loadObject(ofClass: DraggableObject<T>.self) { [weak self] (object, error) in
// This is only called after dropExited delegate method is called !!!
// Before macOS 15.0 it is called quickly after the loadObject method invokation.
asyncOnMainThread {
guard
let self,
let draggableObject = object as? DraggableObject<T>
else { return }
self.onEnter?(draggableObject.object, info.location)
}
}
}
func dropExited(info: DropInfo) {
// Is called as expected.
}
}