How do you Copy
a string to Clipboard
in macOS 10.12 with Xcode 8 and Swift 3?
I am not able to find any reference.
Tap into a text field, highlight the text you want copied and select 'Copy'. Alternatively: Open the Toolbar by tapping the. icon.
Swift 3 you copy it like this way.
let pasteboard = NSPasteboard.general()
pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)
pasteboard.setString("Good Morning", forType: NSPasteboardTypeString)
In Swift 5.2 (on macOS 10.15) the answer is slightly different:
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.string], owner: nil)
pasteboard.setString("Good Morning", forType: .string)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With