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()
}
}
Overview. Xcode 12 includes SDKs for iOS 14, iPadOS 14, tvOS 14, watchOS 7, and macOS Catalina 10.15. 6. The Xcode 12 release supports on-device debugging for iOS 9 and later, tvOS 9 and later, and watchOS 2 and later. Xcode 12 requires an Intel-based Mac running macOS Catalina 10.15.
Xcode doesn't support iOS 15.
Xcode 13 adds powerful new team development features, perfect for working with Xcode Cloud as well as with GitHub, Bitbucket, and GitLab collaboration features.
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+.
if you use SwiftUI (ObservableObject, @EnvironmentObject)
add to previews
.environmentObject(ModelData())
--
struct LandmarkDetail_Previews: PreviewProvider {
static var previews: some View {
LandmarkDetail(landmark: ModelData().landmarks[1])
.environmentObject(ModelData())
}
}
my ModelData
final class ModelData:ObservableObject
{
@Published var landmarks: [Landmark] = load("landmarkData.json")
}
If your SwiftUIView
use ObservableObject
as environmentObject
, try this:
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView().environmentObject(YourObservableObjectClass())
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With