I have been trying to find out how to get the filename of an image dropped into a SwiftUI View.
The code fragment is as follows:
struct MainView: View, DropDelegate {
@ObservedObject var userState : UserState
var body : some View {
Group {
if (self.userState.editing) {
BlackoutView()
} else {
DropView()
}
}
.frame(minWidth: 320, idealWidth: 640, maxWidth: .infinity, minHeight: 240, idealHeight: 480, maxHeight: .infinity, alignment: .center)
.onDrop(of: [(kUTTypeImage as String), "public.pdf"], delegate: self)
}
func dropUpdated(info: DropInfo) -> DropProposal? {
let proposal = DropProposal.init(operation: .copy)
return proposal
}
func performDrop(info: DropInfo) -> Bool {
print("perform drop")
userState.editing = true
return true
}
}
When I drop an image onto the app, it runs performDrop
. How can one obtain the filename of the image dropped onto the app?
It runs on macOS.