Skip to content

Instantly share code, notes, and snippets.

@hawkfalcon
Created May 2, 2018 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawkfalcon/53bde8492ca95c049c694626acf7d732 to your computer and use it in GitHub Desktop.
Save hawkfalcon/53bde8492ca95c049c694626acf7d732 to your computer and use it in GitHub Desktop.
Custom NSSharingService & NSSharingServicePickerDelegate
extension ViewController: NSSharingServicePickerDelegate {
func sharingServicePicker(_ sharingServicePicker: NSSharingServicePicker, sharingServicesForItems items: [Any], proposedSharingServices proposedServices: [NSSharingService]) -> [NSSharingService] {
guard let image = NSImage(named: NSImage.Name("copy")) else {
return proposedServices
}
var share = proposedServices
let customService = NSSharingService(title: "Copy Text", image: image, alternateImage: image, handler: {
if let text = items.first as? String {
self.setClipboard(text: text)
}
})
share.insert(customService, at: 0)
return share
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment