Solved: Reading from clipboard

I am trying to read the text from the clipboard to a string.

I have tried the following code and it writes to the clipboard OK but I can not get it to read the data back into the string.

@IBAction func testButton(_ sender: Any) {
print("Test Started")

    // copy to clipboard
    let pb = NSPasteboard.general
    pb.setString("Hello World!", forType: NSPasteboard.PasteboardType.string)

// This worked solved problem
let cb = NSPasteboard.general.string(forType: .string)



This seems to be about Apple's framework instead of the Swift language itself. You may have better luck over Apple Developer Forums.

1 Like
Terms of Service

Privacy Policy

Cookie Policy