How can we drag views coupled to an NSItemProvider with a custom typeIdentifier or UTI ?
I know you can use the following methods in conjunction with predefined UTI types (like kUTTypeText etc.):
I tried:
But the dropzone does not accept custom UTI's
I also tried to export the custom UTI using Info.plist:
But that did not work either. Then I tried to add it as a document type in Info.plist
Nothing of the above works on macOS. What am I doing wrong?
I know you can use the following methods in conjunction with predefined UTI types (like kUTTypeText etc.):
I tried:
Code Block swift import SwiftUI struct ContentView: View { static let type = "com.devian.sampleapp.customstring.dragdroptype" @State var dropZoneIsHovered = false var body: some View { VStack { Text("Hello") .padding() .onDrag(createItem) Text("Dropzone") .padding() .background(dropZoneIsHovered ? Color.gray : nil) .onDrop( of: [ContentView.type], isTargeted: $dropZoneIsHovered, perform: acceptDrop(items:) ) }.padding() } func createItem() -> NSItemProvider { NSItemProvider( item: "Hello" as NSString, typeIdentifier: ContentView.type ) } func acceptDrop(items: [NSItemProvider]) -> Bool { print("Hurray we received a custom item") return true } }
But the dropzone does not accept custom UTI's
I also tried to export the custom UTI using Info.plist:
Code Block xml <array> <dict> <key>UTTypeConformsTo</key> <array> <string>public.data</string> </array> <key>UTTypeIdentifier</key> <string>com.devian.sampleapp.customstring.dragdroptype</string> <key>UTTypeTagSpecification</key> <dict/> </dict> </array>
But that did not work either. Then I tried to add it as a document type in Info.plist
Code Block xml <array> <dict> <key>CFBundleTypeRole</key> <string>None</string> <key>LSItemContentTypes</key> <array> <string>com.devian.sampleapp.customstring.dragdroptype</string> </array> <key>LSTypeIsPackage</key> <integer>0</integer> </dict> </array>
Nothing of the above works on macOS. What am I doing wrong?