开发者

get string from nspasteboard

开发者 https://www.devze.com 2023-03-08 21:20 出处:网络
maybe it\'s been a long night but I am not able to understand how to check the clipboard for strings

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
0

精彩评论

暂无评论...
验证码 换一张
取 消