SwiftUI Canvas won't build

二次信任 提交于 2020-04-30 07:20:18

问题


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 to build MySwiftUI.swift

clicking on the diagnostics button next to Try Again reveals that it failed with the error:

ld: framework not found FrameworkMyAppUses
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have FrameworkMyAppUses built for simulator and device, and it is in my framework search paths. Building the app to simulator and device both succeed and make use of my framework with no issue, its only the canvas preview that can't build.

If I hit Try again Xcode will tell me Build Succeeded but the canvas preview window continues to just display the framework not found error.

Has anyone else experienced this / knows potential fixes?


回答1:


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.




回答2:


So I had this same issue except it couldn't find my own module... For me the problem was because I have custom build configurations and it didn't like the custom module name. The solution was to rename the module to the same as debug and release in Build Settings > Product Module Name

I hope this helps someone



来源:https://stackoverflow.com/questions/57629916/swiftui-canvas-wont-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!