1

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.

3
  • See answer in Run SwiftUI preview from SPM Package. The reason is the same.
    – Asperi
    May 1, 2020 at 13:14
  • I had an issue that was like this and it had to deal with the library having things not supported in iOS 13. I imported the code directly and made the changes need to the library and every thing started working. Also the only way if found this out was setting the project to iOS 13 target and I added code to exclude sections that did not work. And add in new versions of the code to support iOS 13.
    – MwcsMac
    May 1, 2020 at 13:54
  • @MwcsMac Indeed, I have been writing the SwiftUI code in its own pod and importing it. That lets me build the UI and a fair bit of the business logic. But it'd be nice to be able to develop and preview my views from inside the legacy app workspace itself. May 2, 2020 at 2:41

1 Answer 1

1

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.

1
  • One year more and the same situation, WidgetKit project preview work, but not in general project :)
    – iTux
    Dec 21, 2021 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.