Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read string from clipboard

Tags:

ios

swift

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?

like image 343
Antiokhos Avatar asked Oct 15 '14 07:10

Antiokhos


1 Answers

Just read it back into a variable like this:

let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
    print("String is \(theString)")
}
like image 82
danielbeard Avatar answered Sep 27 '22 19:09

danielbeard