Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to copy text to the clipboard in Swift #928

Open
onmyway133 opened this issue Jul 4, 2023 · 0 comments
Open

How to copy text to the clipboard in Swift #928

onmyway133 opened this issue Jul 4, 2023 · 0 comments
Labels

Comments

@onmyway133
Copy link
Owner

For iOS, use string

Setting this property replaces all current items in the pasteboard with the new item. If the first item has no value of the indicated type, nil is returned.

let pasteboard = UIPasteboard.general
pasteboard.string = "hello world"

For Mac, use clearContents first

Clears the existing contents of the pasteboard, preparing it for new contents. This is the first step in providing data on the pasteboard.

then setString

Sets the given string as the representation for the specified type for the first item on the receiver.
This method invokes setData(_:forType:) to perform the write.

let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(text, forType: .string)
@onmyway133 onmyway133 changed the title How to copy text to the clipboard How to copy text to the clipboard in Swift Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant