Turn your code into a snapshot:
Codeshot creates a beautiful image of your code snippets. Perfect size for Twitter.
Get it now!
There might be a time when you
want to detect whether an app is running in Xcode Previews
or not.
At first, I
expected
something like a
targetEnvironment()
condition that allows us to detect between builds on physical devices and simulators.
#if targetEnvironment(simulator) // code for the simulator here #elseif targetEnvironment(preview) ❌ // code for Xcode Previews here #else // code for real devices here #endif
Sadly, Swift
doesn't provide such a condition
for detecting the Xcode Previews environment.
But we still got some luck. Apple includes a
process environment value
that tells
whether an app is running in the Xcode Previews environment
.
You can easily support sarunw.com by checking out this sponsor.
Turn your code into a snapshot:
Codeshot creates a beautiful image of your code snippets. Perfect size for Twitter.
Feel free to follow me on
Twitter
and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon
https://www.patreon.com/sarunw
and become my supporter. Sharing the article is also greatly appreciated.