本文介绍了从剪贴板读取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从剪贴板中读取字符串并将其写在按钮标题上?我可以使用以下命令将字符串复制到剪贴板:
How can I read a string from the clipboard and write it on a button's title? I can copy a string to the clipboard with:
UIPasteboard.generalPasteboard().string = "Hello world"
但是我如何从剪贴板读取该字符串并将其分配给字符串呢?
But how do I read that string from the clipboard and assign it to a String?
推荐答案
只需将其读回到这样的变量中即可:
Just read it back into a variable like this:
let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
print("String is \(theString)")
}
这篇关于从剪贴板读取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!