Export image from SwiftUI Live Preview in Xcode Canvas

384 views Asked by At

At the time of this writing there is no option in Xcode to export Live Preview in Canvas as PNG image (which would be useful for creating App Store Screenshots).

I'm not sure how this works under the hood but I guess regular simulators are also used in Xcode Canvas for Live Previews. Since it is possible to "Save Screen" from the simulator, I'm wondering is there a way to do the same from Live Previews in Xcode's Canvas?

Can I somehow access those "preview simulators" (ie. via simctl tool) or Xcode's render cache on disk, or is there any other "hacky" way to achieve this before Apple integrates this option in Xcode (which I believe is just a matter of time).

1

There are 1 answers

1
Blazej SLEBODA On

I have tried to save a capture of the view hierarchy as an image to disk, but I was unable to save the file.

Another idea is to use an HTTP connection to upload the view hierarchy image to an HTTP server. I tested it, and it works.