Skip navigation.
 
mlRe: Copying contents of an NSString to the Clipboard
FROM : I. Savant
DATE : Mon Apr 21 19:13:16 2008

>  I've studied the pasteboard docs, and wonder if there is a simple way to
> copy the contents of an NSString to the general clipboard. In AS or AS
> Studio it's just "set the clipboard to <variable>." Is there such a
> convenience method in Cocoa?


  Study the docs again, the answers are there if you've carefully read
the entire document:

http://developer.apple.com/documentation/Cocoa/Conceptual/CopyandPaste/Articles/pbImplementing.html

  Cobbled-together example from example code found in the "Lazy
Writing" section, only slightly modified:

NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *types = [NSArray arrayWithObjects:NSStringPboardType, nil];
[pb declareTypes:types owner:self];
[pb setString:@"Read the docs carefully!" forType:NSStringPboardType];

--
I.S.

Related mailsAuthorDate
mlCopying contents of an NSString to the Clipboard Johnny Lundy Apr 21, 18:58
mlRe: Copying contents of an NSString to the Clipboard I. Savant Apr 21, 19:13