SwiftUI: Automatic Preview Updating Error “Failed to build ContentView.swift”

拈花ヽ惹草 提交于 2020-01-22 10:33:13

问题


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.

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?

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

回答1:


First select the XCode using following command

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

Then run

sudo xcodebuild -license

Hope it is helpful




回答2:


I solved that problem by going to the Xcode - Preferences -> Locations and assigning the Command Line Tools to Xcode 11. Also keep in mind that it is a beta, so it is unstable.




回答3:


I encountered this problem too. I download Xcode beta-1 before I download macOS 10.15. Then after my system upgrade to 10.15, the preview function didn't work. It turns out that Apple has released Xcode beta-2 version recently, so I downloaded and it worked. So, KEEP THE NEWEST VERSION OF XCODE!!!!



来源:https://stackoverflow.com/questions/56448820/swiftui-automatic-preview-updating-error-failed-to-build-contentview-swift

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