7

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!

4
  • 1
    Are you talking about pragmatically copying code from one iOS app in the simulator, and then pasting it into another app in the iOS simulator? If so, 'Xcode' isn't really relevant, as it's merely the IDE, not the language/framework actually being used.
    – Kitsune
    Nov 10, 2013 at 2:05
  • No. I am not intentionally trying to copy the code from one app to another. I am trying to copy a NSString, shareString, from one app and paste it into another.
    – PanicDev
    Nov 10, 2013 at 2:24
  • hm... that code should work. btw, where does this NSString object shareString get it's value from? Also, I'd suggest trying [pasteboard setString:@"test"] just for testing purposes. Nov 10, 2013 at 8:02
  • 1
    Possible duplicate of Copy text to clipboard with iPhone SDK
    – Suragch
    Mar 12, 2016 at 7:25

2 Answers 2

5

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.

0
2

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.