How to access values from the iOS Clipboard (from copy and cut operations)

Screen Shot 2014-09-03 at 16.39.32iOS has a class called UIPasteboard which lets you access the last value that a user has copied or cut to the clipboard (or pasteboard).

The class has a singleton which lets you access a string like so:

This will work fine when any kind of text is involved. Copy/Cut/Paste is also available for images from the Photos app though, and you can access the latest UIImage like this:

Note that those two values are mutually exclusive: if you’ve copied an image, then the text string will be nil, and when you’ve copied text then the image value will be nil.

The UIPasteboard class is very versatile and lets you do all kinds of things – check out the Class Reference for more information:

2 thoughts on “How to access values from the iOS Clipboard (from copy and cut operations)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.