I'm trying to implement a simple drag and drop with NSString. I can get this working with NSURL but not NSString. Every time I try the drag and drop I always end up with a nil value. Here is my code:
struct ContentView: View
{
var body: some View
{
Text("Hello World")
.onDrag { NSItemProvider(object: "Hello World" as NSString) }
}
}
Then the dropped object:
struct DroppedView: View, DropDelegate
{
var body: some View
{
Text("Drop here")
.onDrop(of: ["public.text"], delegate: self)
}
func performDrop(info: DropInfo) -> Bool
{
if let items = info.itemProviders(for: ["public.text"]).first
{
item.loadItem(forTypeIdentifier: "public.text", options: nil)
{
(data, error) in
print(data)
}
}
return true
}
}
I would have expected the output to be "Hello World". What am I missing?