Xcode 11.1 SwiftUI Preview failing

4.5k Views Asked by At

I receive this error whenever I try to preview a freshly created swiftui view.

messageRepliedWithError("Connecting to launched interactive agent 9297", Optional(Error Domain=com.apple.dt.ultraviolet.service Code=17 "connectToPreviewHost: Failed to connect to 9297: Error Domain=com.apple.dt.ProcessAttachUtilities Code=3 "Target process 9297 exited prematurely, likely crashed" UserInfo={NSLocalizedDescription=Target process 9297 exited prematurely, likely crashed}" UserInfo={NSLocalizedDescription=connectToPreviewHost: Failed to connect to 9297: Error Domain=com.apple.dt.ProcessAttachUtilities Code=3 "Target process 9297 exited prematurely, likely crashed" UserInfo={NSLocalizedDescription=Target process 9297 exited prematurely, likely crashed}}))

enter image description here

I have no idea how to fix this so I can see previews again. I am on the latest Catalina 10.15.1

4

There are 4 best solutions below

0
On

I had same issue. It was very confusing. I am using FirebaseFirestore pod in my podfile and when I remove FirebaseApp.configure() from AppDelegate didFinishLaunchingWithOptions function preview works.

I have done this 10 times just to make sure that this is an issue, and it was issue for me. So probably any code from Firbase added in that function was problem for me.

So, by checking logs I came across this error:

Crashed Thread: 3 Dispatch queue: com.google.GDTCORFlatFileStorage

Also googling I came across those bugs:

https://github.com/firebase/firebase-ios-sdk/issues/5707

https://github.com/firebase/firebase-ios-sdk/issues/5708

1
On

Turning off the thread sanitizer worked for me (I was just playing around with settings against another project that worked), so there's one more thing to try...

2
On

I had the same problem with mine, I went through a couple of steps, so I will mention everything I did hopefully it helps someone.

But it's worth mentioning that I think the error was caused by Xcode trying to connect to the preview which failed all the time, because I was using an iPhone 8 preview.

Also I was able to use iPhone 8 preview after a while again. This looks like a buggy Xcode.

Steps. 1. Clean build folder and your derived data. 2. Close XCode Completely. **Key Step. Open Xcode again and change your preview to iPhone XS or iPhone 11. See the image below.

enter image description here

1
On

I found the Preview Canvas to be extremely buggy as well. Or maybe swiftUI code has a lot of undesired side effects.

In many occasions I found that Clean Build Folder, then kill Xcode, start Xcode, do a full Build may (sometimes) fix the problems. Until I make a tiny change somewhere... Then the whole circus starst again.

In practice this is very time consuming and basically unworkable. I found it more efficient to not use the preview canvas at all and just run the code. It is quicker, more reliable and in the end saves lots of time and frustration.

At the same time I think it is a bit of a shame on Apple. Most frustrating of all (for me at least) is that documentation is virtually non existing. It is all trial and error. Mostly error.

In short: my experience is that it is better not to use swiftUI Previews for anything beyond the very basic (yet).