Clipboard.m 789 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Clipboard.m
  3. // MG
  4. //
  5. // Created by Tim Debo on 5/28/14.
  6. //
  7. //
  8. #import "Clipboard.h"
  9. @implementation Clipboard
  10. - (void) copy:(NSString*)text {
  11. [[NSPasteboard generalPasteboard] clearContents];
  12. [[NSPasteboard generalPasteboard] setString:text forType:NSStringPboardType];
  13. }
  14. - (NSString *) paste {
  15. NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
  16. NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
  17. NSDictionary *options = [NSDictionary dictionary];
  18. BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
  19. if (ok) {
  20. NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
  21. return (NSString *) [objectsToPaste objectAtIndex:0];
  22. }
  23. return @"";
  24. }
  25. @end