SwiftUI Canvas 无法构建 [英] SwiftUI Canvas won't build

查看:57
本文介绍了SwiftUI Canvas 无法构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 SwiftUI 代码,当我构建到真正的 iOS 设备或 iOS 模拟器时,它似乎工作得很好.

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

但是在 SwiftUI 画布中,预览显示 Failed to build MySwiftUI.swift

However in the SwiftUI canvas the preview says Failed to build MySwiftUI.swift

点击Try Again旁边的诊断按钮显示它失败并出现错误:

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)

我为模拟器和设备构建了 FrameworkMyAppUses,它在我的框架搜索路径中.将应用程序构建到模拟器和设备都成功并且可以毫无问题地使用我的框架,它只是无法构建的画布预览.

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.

如果我点击 Try again Xcode 会告诉我 Build Succeeded 但画布预览窗口继续只显示框架未找到错误.

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?

推荐答案

终于想通了!

事实证明,它找不到库的原因是因为我使用指向我的项目目录之外某个位置的相对路径来引用它.

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.

我的构建设置的 Framework Search Paths 设置如下:

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.

当我尝试为 SwiftUI 构建时,它一定是从我的根项目目录外部进行的,因此相对框架路径不再正确,并且我得到了问题中显示的错误.

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

这样做是为了可以找到框架.现在我可以成功构建项目,并且我的 SwiftUI 画布会更新.

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

这篇关于SwiftUI Canvas 无法构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆