I want to call .onDrag
and pass it a custom object and I don't want to have to implement NSItemProviderWriting
because it's complicated.
UIKit has a class called UIDragItem
that has a property localObject
. Is it possible to use this or an equivalent with SwiftUI?
I added a UUID
id to my object and created an NSItemProvider
from that.
.onDrag {
NSItemProvider(object: NSString(string: self.clip.id.uuidString))
}
Then I can locate the entity using this Id on a drop.
Even easier is to ignore the NSItemProvider
stuff and pass a closure to a drop delegate...
.onDrag(of: [], delegate: ClipDropDelegate(f: { self.viewModel.changePosition(clip: self.clip) }))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.