Why does Archive fail if there is code for SwiftUI Previews in the Preview Content folder?
I believe this is an Xcode bug, but I've thought of a workaround.
I put all my preview test data in its own PreviewProvider
so that I can access it in other Previews. The Archive still succeeds, and the test data will get stripped in the final Archive. No #if DEBUG
is needed.
Example (specific to my own use case):
struct PreviewData: PreviewProvider { static var previews: some View { Text("This is test data for use in other previews.") } // Use enums for namespacing if desired enum Choices { static let deals = Choice(id: UUID().uuidString, text: "I want the best deals.", iconName: "bestDealsIcon") static let technology = Choice(id: UUID().uuidString, text: "I love technology!", iconName: "technologyIcon") }
Then I can access PreviewData.Choices.deals
in other PreviewProvider
s.