Swift 3 copy line to clipboard

How do you Copy string for Clipboard in macOS 10.12 with xcode 8 and swift 3? I can not find any links.

+5
source share
2 answers

Swift 3 you copy it that way.

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

Here is the pbcopy command, which copies everything that is transferred to it from the terminal to the clipboard.

 echo 'String to copy' | pbcopy 

This will copy "String to copy" to your clipboard.

And you can use this to insert this sting into any file.txt file

 pbpaste > file.txt 
0
source

Source: https://habr.com/ru/post/1260989/


All Articles