Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: Automatic Preview Updating Error "Failed to build 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.

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
like image 419
Ash_B Avatar asked Jun 04 '19 17:06

Ash_B


3 Answers

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

like image 121
tsp Avatar answered Sep 26 '22 04:09

tsp


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.

like image 29
Diego Isco Avatar answered Sep 22 '22 04:09

Diego Isco


I had this problem as I was using // to comment beside my curly brackets to check I had them all in the right spot in my screen code. Xcode seems to cope with a few but once the screen gets too large and too many comments...... Now I comment on the line below and no problems!

like image 3
user2385491 Avatar answered Sep 22 '22 04:09

user2385491