Catalyst Drag and Drop

I am unable to get drag and drop working on Catalyst while the same code works fine on iOS:


func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {

let task = tasksBySection[indexPath.section][indexPath.row]

let itemProvider = NSItemProvider(object: task.taskID as NSString)

let dragItem = UIDragItem(itemProvider: itemProvider)

dragItem.localObject = task

return [dragItem]

}


The drag delegate function completes successfully and then I see the following error messages:


-[__NSCFType _stopDraggingUpdates]: unrecognized selector sent to instance 0x60000370c0c0

2020-03-09 16:32:41.967468-0700 MyApp[57587:599370] -[__NSCFType _setTarget:]: unrecognized selector sent to instance 0x60000370c0c0

2020-03-09 16:32:41.972714-0700 MySpp57587:599370] [General] -[__NSCFType _setTarget:]: unrecognized selector sent to instance 0x60000370c0c0

2020-03-09 16:32:41.991528-0700 MyApp[57587:599370] [General] (

0 CoreFoundation 0x00007fff384778ab __exceptionPreprocess + 250

1 libobjc.A.dylib 0x00007fff6e731805 objc_exception_throw + 48

2 CoreFoundation 0x00007fff384f6b61 -[NSObject(NSObject) __retain_OA] + 0

3 CoreFoundation 0x00007fff383dbadf ___forwarding___ + 1427

4 CoreFoundation 0x00007fff383db4b8 _CF_forwarding_prep_0 + 120

5 AppKit 0x00007fff3593b789 NSCoreDragTrackingProc + 2513

6 HIServices 0x00007fff36605eac DoTrackingMessage + 380

7 HIServices 0x00007fff3660531f CoreDragStartDragging + 939

8 AppKit 0x00007fff3593a720 -[NSCoreDragManager _dragUntilMouseUp:accepted:] + 1304

9 AppKit 0x00007fff35b8b19e _handleBeginDraggingSession + 105

10 CoreFoundation 0x00007fff383fb0ee __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23

11 CoreFoundation 0x00007fff383fb014 __CFRunLoopDoObservers + 457

12 CoreFoundation 0x00007fff383f9b79 CFRunLoopRunSpecific + 409

13 HIToolbox 0x00007fff36f4f65d RunCurrentEventLoopInMode + 292

14 HIToolbox 0x00007fff36f4f39d ReceiveNextEventCommon + 600

15 HIToolbox 0x00007fff36f4f127 _BlockUntilNextEventMatchingListInModeWithFilter + 64

16 AppKit 0x00007fff355bfba4 _DPSNextEvent + 990

17 AppKit 0x00007fff355be380 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352

18 AppKit 0x00007fff355b009e -[NSApplication run] + 658

19 AppKit 0x00007fff35582465 NSApplicationMain + 777

20 AppKit 0x00007fff358a569c _NSApplicationMainWithInfoDictionary + 16

21 UIKitMacHelper 0x00007fff693d08f1 UINSApplicationMain + 322

22 UIKitCore 0x00007fff76278273 UIApplicationMain + 2105

23 MyApp 0x0000000100188c0b main + 75

24 libdyld.dylib 0x00007fff6fa9f7fd start + 1

25 ??? 0x0000000000000003 0x0 + 3

)

Unfortunately I'm seeing exactly the same issue. Did you manage to solve this?

No, not much progress on this yet. I have noticed that if I set a breakpoint and then continue, I don't see the problem.

I spent some time getting to the bottom of this: The root view controller in my macOS catalyst scene was a collection view controller. If I wrap this in a navigation or split view controller, drag works without crashing. It’s not great, but I guess somewhere the parent view controller was being requested by macOS, and there was none... you can turn the navigation bar off in a navigation controller and the fix shouldn’t be noticeable. YMMV though, perhaps there are multiple things that can lead to this issue. Unfortunately even with drag working, drop doesn’t seem to register for me, but this is one step closer. Let me know if drop works for you.

Drop works sporadically - works sometimes, fails sometimes.

For what it's worth I have a Catalyst app which doesn't have any drag and drop support at all. I see a crash with similar entries in the stack trace:


NSCoreDragTrackingProc

DoTrackingMessage

CoreDragStartDragging


Jordansmithnz's suggestion to embed my root view controller in a navigation controller (with hidden bars) worked around the issue. Thank you!


Interestingly, embedding my main view controller in a dummy parent view controller did NOT work. So the problem is not just about a parent view controller being absent.

I upgraded to Xcode 11.4 and Catalina 10.15.4. I'm no longer seeing this. There were also similar crashes that seem to be fixed as well.

same problem on Xcode 11.5 and 10.15.3 , :(
Catalyst Drag and Drop
 
 
Q