5

Drag & drop using onDrag and onDrop from SwiftUI work really well on iOS devices. However, for macOS, I can't even drag a view at all.

For iOS it works, for macOS it doesn't, which seems very strange. This app was made with Catalyst, with an iOS 13.4 target.

Even for something basic it works on one and not the other:

struct ContentView: View {

    var body: some View {
        Text("Hello World!")
            .onDrag { NSItemProvider(object: "Hello 2" as NSString) }
    }
}

What am I doing wrong? Is this a bug?

George
  • 25,988
  • 10
  • 79
  • 133
  • It works... it has no visual feedback while drag in app, but has under droppable area, any text editor accepts drop as expected. – Asperi Apr 27 '20 at 17:54
  • @Asperi For me it's not visual on iOS real device, visual on simulator, but I can't seem to get it working at all on Mac. – George Apr 27 '20 at 18:00
  • Just tested, only copy-pasted your code. Xcode 11.4 / macOS 10.15.4 / macCatalyst 13.4 – Asperi Apr 27 '20 at 18:02
  • @Asperi I'm on Xcode `Version 11.4.1 (11E503a)`... also, how do you see macCatalyst version? – George Apr 27 '20 at 18:05
  • 1
    @Asperi Oh wait - I can drag it out onto the desktop (still invisible). Now I'm confused why it won't drag in the app to the area it would work with in iOS. I'll have more of a look into it! – George Apr 27 '20 at 18:06
  • @Asperi Ok I have developed further. It turns out the issue only occurs when I am using a custom object in `NSItemProvider`. I tried changing the read/write id's, but I got an error say incorrect UTI ids, so it looks like my current one (`com.George-Elsham.Sandbox.ViewItemStore`) is correct. Does this make it easier to know what the problem is, or what I should try next? Stuck on this one – George Apr 27 '20 at 19:41
  • @Asperi I can manage with just using `NSString` instead of my custom `ViewItemStore` class - but is there a way to limit outside sources from dragging into my app then? – George Apr 27 '20 at 19:42
  • Review this topic [Drag and drop with custom type identifier doesn't work](https://stackoverflow.com/a/61225796/12299030) – Asperi Apr 27 '20 at 19:45
  • same code in OP worked for me the first time... – joehinkle11 Feb 24 '21 at 14:41

0 Answers0