Antiokhos
Antiokhos

Reputation: 3045

Read string from clipboard

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?

Upvotes: 16

Views: 6997

Answers (1)

danielbeard
danielbeard

Reputation: 9149

Just read it back into a variable like this:

let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
    print("String is \(theString)")
}

Upvotes: 34

Related Questions