Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy string to clipboard

How do you copy text to the clipboard in xcode? Currently, I am using the following code:

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:shareString];

When I try to paste this into another one of the simulator apps, I end up pasting the entire view controller code. ??? Thanks in advance!

like image 538
PanicDev Avatar asked Nov 09 '13 23:11

PanicDev


People also ask

How do I copy text to clipboard?

Open the file that you want to copy items from. Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.

How do you copy to clipboard variable?

How do I copy a variable to the clipboard? Create an input element and insert the value of variable into it. Select it. Copy it.


2 Answers

Did you refered this link : https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/UsingCopy,Cut,andPasteOperations/UsingCopy,Cut,andPasteOperations.html

The amount of code you have shared seems ok to copy text. May be more code will be helpful to understand your problem. Meanwhile you can go through this link , it is really helpful.

like image 72
Kumar Aditya Avatar answered Sep 19 '22 08:09

Kumar Aditya


In Swift 3.0 you can copy text on PasteBoard and paste anywhere. In short, if you want to copy text programmatically then below code will help you.

let pasteBoard = UIPasteboard.general
pasteBoard.string = "copy the text"
like image 38
Bhavin_m Avatar answered Sep 19 '22 08:09

Bhavin_m