如何从XCode12.2中删除重复的预览?

我是 XCode 的初学者,点击了两次重复预览,现在我找不到删除重复项的方法。我确定这是非常简单的事情,但我一直在搜索和尝试所有事情大约一个小时,但找不到解决方案......

有人可以帮助我吗?

回答

已经找到问题所在了!每次单击重复预览时,它都会在代码中添加一个视图。

下面的代码显示了我的“问题”在哪里:

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
            ContentView()
            ContentView()
        }
    }
}

要解决这个“问题”,只需从代码中删除两个 ContentView() :

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
        }
    }
}

  • This is actually a good beginner question and answer, but it needs more clarity and detail. Please modify your question to be more clear that the issue was cause by your code and not the interface (include example code - not just screenshots). Then. in your answer, show the code that caused the problem so other beginners may see this and learn from it...

以上是如何从XCode12.2中删除重复的预览?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>