objective-cclipboardnspasteboard

get string from nspasteboard


maybe it's been a long night but I am not able to understand how to check the clipboard for strings

I have been reading the NSPasteboard documentation..

could some one help me out?


Solution

  • you need to use the following method with stringForType with key NSPasteboardTypeString to read the string value from clipboard.

    - (NSString *)stringForType:(NSString *)dataType .

    NSPasteboard*  myPasteboard  = [NSPasteboard generalPasteboard];
    NSString* myString = [myPasteboard  stringForType:NSPasteboardTypeString];
    

    To do this for iOS with UIPasteBoard use the following code:

    UIPasteboard *thePasteboard = [UIPasteboard generalPasteboard];
    NSString *pasteboardString = thePasteboard.string;
    NSLog(@"%@", pasteboardString);