Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs don't mention that previews only work in debug builds #220

Open
CraigSiemens opened this issue Jan 19, 2025 · 2 comments
Open

Docs don't mention that previews only work in debug builds #220

CraigSiemens opened this issue Jan 19, 2025 · 2 comments

Comments

@CraigSiemens
Copy link

I was curious if I'd be able to show the gallery in the TestFlight build of our app to simplify sharing it with designers. I suspected it wouldn't work since Xcode should be removing the previews as part of the optimization, but this tool has enough magic in it, I wasn't 100% sure. I couldn't find it mentioned in the readme one way or the other.

I made a release build and ran it on the simulator and confirmed that no previews were shown in the gallery.

It would be a nice improvement if the readme mentioned that it the gallery only works for debug builds. Also potentially including instructions for removing this as a dependency for release builds since it's not useable and potentially leads to a larger app size.

@noahsmartin
Copy link
Member

Hey @CraigSiemens this depends on exactly how you write your previews and what build settings you use. For example you could do this:

#if DEBUG
struct MyPreviews: PreviewProvider { ... }
#endif

And then it would only be included when DEBUG=1 but you could also replace DEBUG with something like ALPHA and have a config that enables them.

Alternatively you could use dead code stripping to remove previews, then you can create a new build config that turns off dead code stripping but has whatever other settings you need. I've heard from other users that a common setup is to have debug/alpha build configs that include previews and other internal-only features, and then an App Store config that only has production features.

@CraigSiemens
Copy link
Author

CraigSiemens commented Jan 21, 2025

After experimenting with the DemoApp some more, it appears that previews are removed with the following build settings. All I changed was the scheme's run build configuration to Release.

These are the settings that seems to control removing the previews. Changing either one will cause the previews to be present again.

SWIFT_COMPILATION_MODE = wholemodule
SWIFT_OPTIMIZATION_LEVEL = -O

None of the previews are in a #if DEBUG so that doesn't have any effect.

It also appears like DEAD_CODE_STRIPPING is set to NO in the DemoApp, so the previews are removed without it being enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants