让我们假设在UIPasteBoard上复制了3个字符串:
UIPasteboard.generalPasteboard().string="hello"
UIPasteboard.generalPasteboard().string="world"
UIPasteboard.generalPasteboard().string="!"我使用UIPasteboard.generalPasteboard().string="“
油漆板能洗干净吗?UIPasteBoard是否有类似于NSPasteBoard的clearContents()功能?
发布于 2016-04-03 13:07:47
如果您知道您的程序是唯一一个操作特定pasteboard的程序,那么是的,将string属性设置为""将有效地清除pasteboard。
您可以很容易地在游乐场测试这一点。
var pb = UIPasteboard.generalPasteboard()
pb.string = "hello"
pb.string
pb.items
pb.string = ""
pb.string
pb.items哪种输出
<UIPasteboard: 0x7fed6bd0a750>
<UIPasteboard: 0x7fed6bd0a750>
"hello"
[["public.utf8-plain-text": "hello"]]
<UIPasteboard: 0x7fed6bd0a750>
nil
[[:]]但是,请注意,string属性UIPasteboard是字符串类型的第一个pasteboard项的简写。类型字符串的所有项都可以通过strings属性访问。
所有底层的pasteboard项目都是在items属性中建模的,这是一个[String: AnyObject]类型字典的数组。每个字典都在键值中包含对象的类型信息,在值中包含pasteboard值。
因为您使用的是一个系统范围的generalPasteboard,所以它也可以被其他程序操作,因此,要清除黑板上的所有项目,您应该使用
UIPasteboard.generalPasteboard().items = []如果您要将纸板用于内部应用程序,则创建内部纸板要比使用系统范围的generalPasteboard更好。请参阅pasteboardWithUniqueName()
https://stackoverflow.com/questions/36384506
复制相似问题