If you’ve been forced to run Xcode through Rosetta (for example, because a binary framework vendor has been extraordinarily slow to adopt the xcframework format or simply isn’t including the right simulator slice), you may have noticed that copy and pasting inside the simulated app isn’t working. My knowledge of macOS isn’t deep enough to say why exactly that is, but the error messages in the debug console point to some sort of XPC/permissions issue. The copied contents are written to a disk cache, but can’t be read back for some reason. I assume it has something to do with the simulator itself running natively, while the app runs through Rosetta.

Regardless, for those of us who suffer from this issue or otherwise find the pasteboard sync between macOS and the simulator unreliable, I developed a small helper class you can drop into your project. It’s designed to be excluded automatically from release builds and not activate outside the simulator.

Simulated apps aren’t meaningfully isolated1 from the host system, which allows an app to monitor files outside its container. The helper by default creates an empty file inside your home directory and makes any text you save inside this file available for pasting inside the app with a special keyboard shortcut.

There’s a few enhancements I can think of, such as syncing automatically by running an agent that monitors the host system pasteboard. It should also be possible to make data move in the other direction, from the simulated app to the monitored file. However, the helper covers the most common use case for now.

I hope you find it useful.

SimPasteboardHelper on Github

  1. This can be a confounding factor with build issues where a dynamic framework isn’t copied into the app binary. It will still work in the simulator because the app can load the framework from the derived data directory, but will crash when running on device.