Skip to content

Instantly share code, notes, and snippets.

@pilky
Created May 25, 2020 12:28
Show Gist options
  • Save pilky/c3d9e7223c797fd4f219eb1d0231e0c1 to your computer and use it in GitHub Desktop.
Save pilky/c3d9e7223c797fd4f219eb1d0231e0c1 to your computer and use it in GitHub Desktop.
NSFilePromiseProvider that supports additional types
class ExtendableFilePromiseProvider: NSFilePromiseProvider {
var additionalItems: [NSPasteboard.PasteboardType: Any] = [:]
override func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
var types = super.writableTypes(for: pasteboard)
if self.additionalItems.count > 0 {
types.append(contentsOf: self.additionalItems.keys)
}
return types
}
override func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? {
if let item = self.additionalItems[type] {
return item
}
return super.pasteboardPropertyList(forType: type)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment