从nspasteboard获取字符串

问题描述

| 也许已经过了一个漫长的夜晚,但我无法理解如何检查剪贴板中的字符串 我一直在阅读NSPasteboard文档。 有人可以帮我吗?     

解决方法

        您需要对stringForType和NSPasteboardTypeString键使用以下方法,以从剪贴板读取字符串值。
- (NSString *)stringForType:(NSString *)dataType
NSPasteboard*  myPasteboard  = [NSPasteboard generalPasteboard];
NSString* myString = [myPasteboard  stringForType:NSPasteboardTypeString];
要使用UIPasteBoard在iOS上执行此操作,请使用以下代码:
UIPasteboard *thePasteboard = [UIPasteboard generalPasteboard];
NSString *pasteboardString = thePasteboard.string;
NSLog(@\"%@\",pasteboardString);
    ,        您可以在下面找到适用于Mac和iOS的Swift 4版本。 苹果电脑
    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
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...