SwiftUI Preview Canvas Build Fails but Project Build does Not

1.4k views Asked by At

I am working on a project to add SwiftUI to a legacy app that uses Cocoapods. When I try to run the preview canvas the build fails and the canvas cannot run.

The cause is an issue building one of the included pods in the project (we’ll call this pod ‘LibraryX’). When XCode tries to build LibraryX it encounters a segmentation fault. But when I build the project itself there is no problem building LibraryX and starting the app.

I have tried looking for SwiftUI-preview-specific build settings in the XCode project build settings and have not been able to find anything. I have double checked the build path settings (as in this answer) and also verified that I am building on the correct device (as in this answer). In general, Googling for others who are facing similar issues has not turned up anything like my issue so far.

What I am wondering then is this: Does XCode use different build settings for building the project for use in creating the preview canvas? If so is there some way to configure how the preview canvas build works?

Because LibraryX is proprietary and the SwiftUI view I’m trying to add is simply the default “hello world” view that XCode creates there is not much I can share in the way of code samples for this question.

1

There are 1 answers

1
Kuhlemann On

SwiftUI has still some bugs and is not perfect yet. The canvas is part of SwiftUI and "shares" some of these bugs. Sometimes you find yourself in a situation, where (a.) something does not work on Canvas or (b.) does not work correct on the simulator but (c.) works on a real device perfectly. Most likely everything will get better over time, because SwiftUI is quite new (less then a year old) and Apple is pushing it.

My "solution" for the moment in similar situations is to not rely on canvas and just test on simulator.