Copy NSString to Clipboard

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

NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSArray *types = [NSArray     arrayWithObjects:NSStringPboardType, nil];
[pb declareTypes:types owner:self];
[pb setString: str forType:NSStringPboardType];

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.