Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct PasteButtonView: View {
let utType: UTType
@Binding var text: String
var body: some View {
PasteButton(supportedContentTypes: [utType]) { array in
guard let firstItem = array.first else { return }
//The type for our text property is "public.utf8-plain-text"
print(getUTITypeString(for: text))
firstItem.loadDataRepresentation(forTypeIdentifier: utType.identifier) {
(data, error) in
if let data = data { self.text = String(decoding: data, as: UTF8.self) }
}
}
.padding()
}
func getUTITypeString(for item: Any) -> [String] {
if let item = item as? NSItemProviderWriting {
return NSItemProvider(object: item).registeredTypeIdentifiers
} else { return [String]() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment