Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active February 11, 2020 10:47
Show Gist options
  • Save sturdysturge/79c73600cfb683663c1d70f5c0778020 to your computer and use it in GitHub Desktop.
Save sturdysturge/79c73600cfb683663c1d70f5c0778020 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var text = String()
var body: some View {
VStack {
Text(text)
PasteButton(supportedTypes: ["public.utf8-plain-text"], payloadAction: { array in
array.first!.loadDataRepresentation(forTypeIdentifier: "public.utf8-plain-text", completionHandler: {
(data, error) in
guard let data = data else {
return
}
let loadedText = String(decoding: data, as: UTF8.self)
self.text = loadedText
//This call just shows how to find print the UTI type of any type conforming to NSItemProviderWriting, "public.utf8-plain-text" in this case
self.getUTITypeString(for: loadedText)
})
})
}
.frame(width: 200, height: 200)
}
func getUTITypeString(for item: Any) {
if let item = item as? NSItemProviderWriting {
let provider = NSItemProvider(object: item)
print(provider)
}
else {
print("This data type cannot be used in an NSItemProvider")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment