Swift 3 copy string to clipboard
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)
Swift 3 you copy it like this way.
let pasteboard = NSPasteboard.general()
pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)
pasteboard.setString("Good Morning", forType: NSPasteboardTypeString)