Archive Build Requires 'Preview Content'

Does an 'archive build' require 'preview content'?

I've put swift source files into 'Preview Content' directories - one directory for the top-level App and one for an embedded framework. An 'archive build' fails, complaining about the code in a #Preview block.

#Preview {
    // the archive build fails to find this `default` ??
    let controller = PersistenceControllerTopLevelPreview.default
    let user = controller.user
    ...

The framework has its 'Preview Context' specified in the Development Assets; same with the top-level App.

Accepted Reply

Hi,

#Preview and its predecessor PreviewProvider tend to get dead code stripped when building for release, but there are projects where lingering references might cause them to stick around. Best way to be sure they are only present in debug builds would be to wrap the definitions like so:

#if DEBUG
#Preview {
    …
}
#endif

Hope that helps.

  • So at least my expectation was correct. #if DEBUG ... #endif does allow the Archive build to complete

Add a Comment

Replies

Hi,

#Preview and its predecessor PreviewProvider tend to get dead code stripped when building for release, but there are projects where lingering references might cause them to stick around. Best way to be sure they are only present in debug builds would be to wrap the definitions like so:

#if DEBUG
#Preview {
    …
}
#endif

Hope that helps.

  • So at least my expectation was correct. #if DEBUG ... #endif does allow the Archive build to complete

Add a Comment