Copy NSString to Clipboard

Filed under Cocoa + Objective-C on Sunday, 20 September, 2009 12:09 pm

Coming back to the ultimate purpose of this blog... helping my memory! :D
Here we are: a code snippet to copy a NSString to the clipboard...

-(void)copyToClipboard:(NSString*)str
{
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *types = [NSArray     arrayWithObjects:NSStringPboardType, nil];
[pb declareTypes:types owner:self];
[pb setString: str forType:NSStringPboardType];
}