How to copy text to the clipboard in iOS

⋅ 1 min read ⋅ UIKit

Table of Contents

What is pasteboard

Pasteboard (or Clipboard) is a term that refers to a place that lets users share data from one place to another.

The most common scenario is copying text from one app and pasting it to other apps.

You can easily support sarunw.com by checking out this sponsor.

Sponsor sarunw.com and reach thousands of iOS developers.

How to copy text to the pasteboard in iOS

To copy text from your app, you need to write it down to the systemwide general pasteboard.

You can access it from UIPasteboard.general.

Here is how you copy text "123456" to the pasteboard. You just set a string to the general pasteboard like a normal property.

UIPasteboard.general.string = "123456"

That's all you need to do to copy text to the pasteboard.

You can easily support sarunw.com by checking out this sponsor.

Sponsor sarunw.com and reach thousands of iOS developers.

How to read the data back from the pasteboard in iOS

To read the text back, we can read it from the same property.

if let text = UIPasteboard.general.string {
print(text)
}

Read more article about UIKit or see all available topic

Enjoy the read?

If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.

Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.

If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.

Become a patron Buy me a coffee Tweet Share
Previous
How to request users to review your app in UIKit

Learn how and when you should ask for a user's review.

Next
How to request users to review your app in SwiftUI

Learn how and when you should ask for a user's review.

← Home