SwiftUI 预览因链接器错误而失败 [英] SwiftUI Preview fails with linker errors

查看:41
本文介绍了SwiftUI 预览因链接器错误而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 SwiftUI 视图添加到现有的基于 UIKit + Storyboards 的 tvOS 项目中.实际 构建运行良好,我可以在模拟器中运行 &查看我的 SwiftUI 视图,但是当我恢复 SwiftUI 预览时,我收到无法构建 MyClass.swift",诊断如下:

I've trying to add a SwiftUI view to an existing UIKit + Storyboards based tvOS project. The actual build works fine and I can run in the simulator & see my SwiftUI view, but when I resume the SwiftUI preview I get 'Failed to build MyClass.swift' with the following diagnostics:

我看到了这个类似的 SO 帖子关于-bundle 和 -bitcode_bundle 不能一起使用 错误,但我的配置已经是答案建议的方式(将 Mach-O 类型设置为 Executable 并确保未设置 Bundle Loader).

I saw this similar SO post regarding the -bundle and -bitcode_bundle cannot be used together error, but my configuration is already the way the answer suggests (setting the Mach-O type to Executable and ensuring no Bundle Loader is set).

还有一个关于 /Applications/Xcode.app/Contents/SharedFrameworks-appletvsimulator 没有找到的警告.该目录当然不存在,但我的项目中没有任何地方引用了我可以找到的 SharedFrameworks-appletvsimulator.此外,如果我创建一个新的 SwiftUI 项目,它也不会抱怨.

There's also a warning about /Applications/Xcode.app/Contents/SharedFrameworks-appletvsimulator not being found. That directory certainly does not exist, but nowhere in my project is SharedFrameworks-appletvsimulator referenced that I can find. Also, if I create a new SwiftUI project it doesn't complain about that.

SwiftUI 代码实际上只是来自 Xcode 模板的一个新的Hello World"SwiftUI 文件 - 我根本没有修改它.

The SwiftUI code is literally just a new "Hello World" SwiftUI file from the Xcode template - I haven't modified it at all.

有没有人知道这里发生了什么或如何解决它?

Does anyone have any ideas what's going on here or how to fix it?

推荐答案

对我来说,修复是禁用代码覆盖选项:

For me the fix was disabling the code coverage option:

转到您的方案菜单 ->选择编辑方案 ->进入测试"左侧菜单部分 ->取消选中代码覆盖率标记

Go to your scheme menu -> select edit scheme -> go to the "Test" section on the left side menu -> uncheck the Code Coverage mark

  • 我使用的是 Xcode 12.5
  • iOS 最低目标 13.4

预览失败的原因有很多,并且有几篇关于它的帖子,例如:这个问题

There are diffrent reasons for the preview to fails and several posts about it , for example: This Question

这篇关于SwiftUI 预览因链接器错误而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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