问题描述
每当我尝试预览新创建的 swiftui 视图时都会收到此错误.
I receive this error whenever I try to preview a freshly created swiftui view.
messageRepliedWithError("连接到已启动的交互代理 9297", Optional(Error Domain=com.apple.dt.ultraviolet.service Code=17 "connectToPreviewHost: 无法连接到 9297: Error Domain=com.apple.dt.ProcessAttachUtilities代码=3目标进程 9297 过早退出,可能崩溃" UserInfo={NSLocalizedDescription=目标进程 9297 过早退出,可能崩溃}" UserInfo={NSLocalizedDescription=connectToPreviewHost:无法连接到 9297:错误域=com.apple.dt.ProcessAttachUtilities Code=3目标进程 9297 过早退出,可能崩溃" UserInfo={NSLocalizedDescription=目标进程 9297 过早退出,可能崩溃}}))
我不知道如何解决这个问题,所以我可以再次看到预览.我在最新的 Catalina 10.15.1
I have no idea how to fix this so I can see previews again. I am on the latest Catalina 10.15.1
推荐答案
我发现预览画布也有很多问题.或者,swiftUI 代码可能有很多不受欢迎的副作用.
I found the Preview Canvas to be extremely buggy as well. Or maybe swiftUI code has a lot of undesired side effects.
在很多情况下,我发现清理构建文件夹,然后杀死 Xcode,启动 Xcode,执行完整构建可能(有时)解决问题.直到我在某处做了一个微小的改变……然后整个马戏团又开始了.
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.
与此同时,我认为这对 Apple 来说有点可惜.最令人沮丧(至少对我而言)是文档几乎不存在.这都是反复试验.主要是错误.
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.
简而言之:我的经验是,最好不要将 swiftUI Previews 用于非常基本(尚未)之外的任何内容.
In short: my experience is that it is better not to use swiftUI Previews for anything beyond the very basic (yet).
这篇关于Xcode 11.1 SwiftUI 预览失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!