Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPasteboard - cannot copy text

This code should copy the string to the generalPasteboard, as the [[UIPasteboard generalPasteboard] string] object, but the method causes the program to terminate.

- (void)copyResultToPasteboard {
    NSString *message = self.resultTextView.text;
    [UIPasteboard generalPasteboard].string = message;
    [message release];
}

I think it's something to do with format, seeing as the method works if the message is set to a literal string, but resultTextView.text is just an NSString... I don't fully understand, can anyone help?

like image 475
Boz Avatar asked Sep 07 '09 12:09

Boz


People also ask

How do you copy text in Swift?

Tap into a text field, highlight the text you want copied and select 'Copy'. Alternatively: Open the Toolbar by tapping the. icon.

What is Uipasteboard?

An object that helps a user share data from one place to another within your app, and from your app to other apps.


1 Answers

Are you sure that resultTextView.text is returning a copy of the backing store, and not the actual NSString* used to store the data? Looking over the Apple documentation, it seems likely it's just returning the internal pointer (unretained). Calling release on a string being used by the UITextView class could cause this behaviour.

like image 90
Adam Wright Avatar answered Sep 23 '22 03:09

Adam Wright