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…

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

Leave a Reply

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