I am also having this issue, with the same console message as @texasexile. My code:
struct ContentView: View {
@State private var names: [NSString] = ["John","Hunter","Mark","Tom","Jeremy","Bill","Frank"]
@State private var isTargeted: Bool = false
let string = NSString("Test")
var body: some View {
GeometryReader { g in
VStack(alignment: .leading) {
ForEach(names, id: \.self) { name in
HStack {
Text(name as String)
.padding()
Spacer()
}
.border(Color.black)
.onDrag {
NSItemProvider(item: name, typeIdentifier: UTType.modelName.identifier)
}
}
}
.onDrop(of: [UTType.modelName], delegate: Delegate(list: $names))
.padding()
}
}
}
struct Delegate: DropDelegate {
@Binding var list: [NSString]
func performDrop(info: DropInfo) -> Bool {
guard info.hasItemsConforming(to: [UTType.modelName]) else {
return false
}
let providers = info.itemProviders(for: [UTType.modelName])
if let provider = providers.first {
provider.loadItem(forTypeIdentifier: UTType.modelName.identifier) { (name: NSSecureCoding?, error: Error?) in
if let name = name as? NSString {
list.append(name)
/* This part isn't finished */
}
}
}
return true
}
}
extension UTType {
static let modelName: UTType = UTType("model.name")!
}
I am using NSString in this example, but I'm only doing this to test with a type conforming to NSSecureCoding since I was having issues in a more complicated sample.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: