Search code examples
swift3xcode8macos-sierranspasteboard

Swift 3 copy string to clipboard


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.


Solution

  • Swift 3 you copy it like this way.

     let pasteboard = NSPasteboard.general()
     pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)
     pasteboard.setString("Good Morning", forType: NSPasteboardTypeString)