SwiftUI Canvas won't build

后端 未结 2 544
轻奢々
轻奢々 2021-01-28 13:36

I have some SwiftUI code and it seems to work great when I build to a real iOS device or to an iOS simulator.

However in the SwiftUI canvas the preview says Failed

2条回答
  •  渐次进展
    2021-01-28 13:54

    Finally figured it out!

    So it turns out, the reason it couldn't find the library was because I was referencing it with a relative path to a spot outside of my project directory.

    My build settings had the Framework Search Paths set up like this:

    ../path/to/my/framework

    And when I normally built my project this worked fine and it would find the framework. So it seems as though by default my build script is run from my project directory.

    When I tried to build for SwiftUI, it must have been doing so from outside my root project directory so the relative framework path so no longer correct and I got the error shown in the question.

    Updating the framework search path to a (slightly less relative?) path like this:

    $(PROJECT_DIR)/../path/to/my/framework

    made it so the framework could be found. Now I can successfully build the project and my SwiftUI canvas updates as it should.

提交回复
热议问题