9
votes

Seems like previews stopped working on Xcode 12! Trying to preview the SwiftUI file template and getting the error below. Any ideas how to fix this? Tried cleaning the build folder, deleting derived data and restarting Xcode to no avail!

On Catalina 10.15.6.

RemoteHumanReadableError: Failed to update preview.

The preview process appears to have crashed.

Error encountered when sending 'prepare' message to agent.

==================================

|  RemoteHumanReadableError: The operation couldn’t be completed. (BSServiceConnectionErrorDomain error 3.)
|  
|  BSServiceConnectionErrorDomain (3):
|  ==BSErrorCodeDescription: OperationFailed

The code I am trying to preview (from SwiftUI new file template):

import SwiftUI

struct SwiftUIView: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}
3
Seems like an Xcode error, cleaning derived data might help or just restarting Xcode - Itay Brenner
Deleted all that I could, derived data, build folder.& restarted Xcode several times, nope, still not working! - Zorayr
Could it be that you enabled Preview on Device? I know it isn’t helpful but that Xcode error may happen due to lots of reasons - Itay Brenner
I toggled preview on device on/off, but still can't get it to work. Actually, seems like this is a common issue with Xcode 12, lots of people reporting preview issues but no solution in the horizon! - Zorayr
Did you try to erase Xcode Application state beside the derived data? The Xcode Application State is saved on path ~/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState - kerim.ba

3 Answers

5
votes

If your SwiftUIView use ObservableObject as environmentObject, try this:

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView().environmentObject(YourObservableObjectClass())
    }
}
2
votes

Apparently it was a bug with Firestore, which is most likely the cause: XCode 12 Preview Crashes when adding Firebase SDK Swift UI 2.0. The best solution at this point is to call, pod update which should solve the issue. I verified on Xcode 12, iOS 13+.

-1
votes

I had the same issue when I updated Firebase Analytics (to v6.33.0). Commenting out the following line fixed it.

FirebaseApp.configure()