6

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?

Boz
  • 1,646
  • 5
  • 15
  • 15

2 Answers2

3

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.

Andriy
  • 2,767
  • 2
  • 21
  • 29
Adam Wright
  • 48,938
  • 12
  • 131
  • 152
3

You're sending -release to an object which you didn't (or at least, which it doesn't appear you have, from the snippit) first -retain, +alloc or get through -copying another object.