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 re开发者_开发技巧ading the NSPasteboard documentation..
could some one help me out?
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);
You can find the Swift 4 version on below for both Mac and iOS.
Mac
let pasteboard = NSPasteboard.general
let copiedString = pasteboard.string(forType: .string)
iOS
let pasteboard = UIPasteboard.general
let copiedString = pasteboard.string // might be nil value, is an optional variable
精彩评论