"The clipboard the user had might be an image, a file, rich text. Borrow all of it, give all of it back."
The Clipboard Is Not a String
The probe borrows the clipboard, so the restore has to return it faithfully — and here's the trap: the clipboard is not just plain text. At any moment it may hold an image, files, rich text, HTML, or a custom type from some app, often several representations of the same thing at once. If your restore only saved and rewrote the plain-text string, then a user who had an image or a set of files on the clipboard gets it silently destroyed by your probe. 'Reversible' has to mean reversible for whatever they actually had, not just for text.
Snapshot Every Item, Every Type
A full capture walks the pasteboard's items — there can be more than one — and for each item records every type it advertises together with that type's data. That map of items-to-types-to-data is the real snapshot. Restoring is the mirror image: clear the pasteboard and write those items back with all their types intact. Do it this way and an image survives as an image, files survive as files, rich text keeps its formatting — the user's clipboard comes back byte-for-byte, not flattened to a string.
NAIVE (loses everything but text):
save pb.string(forType: .string)
...probe...
restore pb.setString(saved, forType: .string) // image/files GONE
FAITHFUL:
save every item -> every type -> its data
...probe...
restore rebuild each item with all its types, write them back
When You Can't Fully Capture
Honesty check: some clipboard contents can't be fully snapshotted — promised or lazily-provided data, where the source app hands over the bytes only when a paste actually happens. You cannot always capture those up front. The conservative rule is: if you can't snapshot the entire pasteboard with fidelity, don't run the destructive probe at all — fall back to whatever you could read another way, and leave the clipboard alone. It is better to miss a selection than to eat a user's copied file. Preservation is all-or-nothing: full fidelity, or don't touch it.