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!

Kitsune
  • 9,101
  • 2
  • 25
  • 24
PanicDev
  • 315
  • 1
  • 4
  • 12
  • 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 '13 at 02: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 '13 at 02: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. – staticVoidMan Nov 10 '13 at 08:02
  • 1
    Possible duplicate of [Copy text to clipboard with iPhone SDK](http://stackoverflow.com/questions/1479468/copy-text-to-clipboard-with-iphone-sdk) – Suragch Mar 12 '16 at 07:25

2 Answers2

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.

Kumar Aditya
  • 1,097
  • 1
  • 8
  • 19
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"
Bhavin_m
  • 2,746
  • 3
  • 30
  • 49