Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created April 2, 2020 07:09
Show Gist options
  • Save wizard1066/54370b55f7db8ac76e3db485843e13f6 to your computer and use it in GitHub Desktop.
Save wizard1066/54370b55f7db8ac76e3db485843e13f6 to your computer and use it in GitHub Desktop.
abgwtp4
struct TheDropDelegate: DropDelegate {
@Binding var textText:String
func validateDrop(info: DropInfo) -> Bool {
return info.hasItemsConforming(to: ["public.utf8-plain-text"])
}
func dropEntered(info: DropInfo) {
print("drop entered")
}
func performDrop(info: DropInfo) -> Bool {
if let item = info.itemProviders(for: "public.utf8-plain-text").first {
item.loadItem(forTypeIdentifier: "public.utf8-plain-text", options: nil) { (urlData, error) in
DispatchQueue.main.async {
if let urlData = urlData as? Data {
let text = String(decoding: urlData, as: UTF8.self)
self.textText = text
}
}
}
return true
} else {
return false
}
}
func dropUpdated(info: DropInfo) -> DropProposal? {
print("drop Updated")
return nil
}
func dropExited(info: DropInfo) {
print("dropExited")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment