Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 11.1 SwiftUI Preview failing

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

like image 624
Rob Avatar asked Oct 31 '19 15:10

Rob


2 Answers

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).

like image 73
Johannes Avatar answered Sep 21 '22 03:09

Johannes


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

like image 38
GyroCocoa Avatar answered Sep 23 '22 03:09

GyroCocoa