Would the general iPhone pasteboard ever contain more than one item?

1.6k views Asked by At

Would pasteboard.numberOfItems (in the code below) ever be greater than 1? How would the user cause this to happen?

UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
pasteBoard.numberOfItems

Note that I'm not asking if a single pasteboard item can have more than one representation type. That they can is clear.

Update: I understand that programmatically one could put more than one item in the pasteboard (using addItems as Kevin Ballard points out, or by setting the items property to an array containing more than one dictionary). But could the user do this using any of the built-in apps? I suppose one could easily write an app that puts more than one item in the pasteboard (so for my app to be robust, it should handle that situation).

3

There are 3 answers

0
Mike Camilo On BEST ANSWER

The built-in Photos app allows you to place multiple photos on the general pasteboard. Just use the "Share" button, select several photos, and then press "Copy".

The general pasteboard will then have each photo as an item with two representations: "public.jpeg" and "public.utf8-plain-text". The second representation (text) seems to be a file name, however in this case Photos always returns "image" plus a sequential number (i.e. image1.jpg, image2.jpg, etc.).

In addition, the user may use a clipboard app (several of which are present in the App store) to place multiple items in the general pasteboard. I'm currently building a clipboard sharing app.

1
Lily Ballard On

There's an -addItems: method on UIPasteboard, so I think it's pretty clear that it's certainly possible to have multiple items.

1
mjhoy On

Not with Apple's provided apps. It's entirely possible for a third party app to add multiple items as far as I know.

EDIT: On second thought, I may have had multiple items a few times while testing my app, but I didn't determine from where, or whether it was an Apple app. In either case, I'd write a test for it. My app -- right now -- only looks at the first item, and I've never had problems with built in apps in testing.