Xcode 11.1 SwiftUI Preview failing

走远了吗. 提交于 2020-03-03 10:10:31

问题


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

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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/58646233/xcode-11-1-swiftui-preview-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!