SwiftUI:自动预览更新错误“无法构建 ContentView.swift" [英] SwiftUI: Automatic Preview Updating Error "Failed to build ContentView.swift"

查看:40
本文介绍了SwiftUI:自动预览更新错误“无法构建 ContentView.swift"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Xcode 11 中运行自动预览,但是即使项目成功构建,自动预览也失败给我错误 无法构建 ContentView.swift.未能对 ContentView.swift 进行编码签名.

I'm trying to run the Automatic Preview in Xcode 11, however even though the project builds successfully, the automatic preview fails giving me the error Failed to build ContentView.swift. Failed to code sign ContentView.swift.

我刚刚创建了项目,没有对自动生成的代码进行任何修改.甚至代码签名也已正确设置.请注意,我使用的是免费 Apple 开发者帐户.这会导致任何问题吗?

I have just created the project without any modifications to the auto generated code. Even the code signing has also been set properly. Note I'm using the Free Apple Developer Account. Could this cause any problem?

以下是 ContentView.swift 文件中的代码:

Following is the code from ContentView.swift file:

import SwiftUI

struct ContentView : View {
    var body: some View {
        Text("Hello World")
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

推荐答案

首先选择Xcode 使用以下命令

First select the Xcode using following command

sudo xcode-select -s/Applications/Xcode.app/Contents/Developer

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

然后运行

sudo xcodebuild -license

sudo xcodebuild -license

希望对你有帮助

这篇关于SwiftUI:自动预览更新错误“无法构建 ContentView.swift"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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