Created
May 2, 2018 23:09
-
-
Save hawkfalcon/53bde8492ca95c049c694626acf7d732 to your computer and use it in GitHub Desktop.
Custom NSSharingService & NSSharingServicePickerDelegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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