如何调试“前提条件失败”?在Xcode中? [英] How to debug "precondition failure" in Xcode?

查看:110
本文介绍了如何调试“前提条件失败”?在Xcode中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Xcode 11上构建一个SwiftUI应用程序,但是当我切换到应用程序中的特定选项卡时,它会立即终止。

I'm building a SwiftUI App on Xcode 11 but is terminating immediately whenever I switch to a particular tab in the app.

事实是,它始终指向 Application Delegate 文件,我认为这并不是真正的问题。我也在控制台前提条件失败:错误的输入索引:2 中收到此错误,仅此而已,没有更多关于此错误的文件,数组或函数的详细信息

Thing is, it always points to the Application Delegate file, which I think is not really the problem. I'm also getting this error in the console precondition failure: invalid input index: 2 and that's it, no more additional details on what file, array, or function this error is coming from.

Xcode中是否有任何方法找出导致此问题的原因?

Is there any way in Xcode to isolate which is causing this problem?

推荐答案

我有一个TabView,其中包含使用列表的视图。
切换选项卡时,我的应用程序崩溃时发生类似错误:
前提条件失败:属性未能设置初始值:99
这崩溃了:

I had a TabView containing a view that used a List. When switching tabs, my app was crashing with a similar error: "precondition failure: attribute failed to set an initial value: 99" This crashed:

var body: some View {
    TabView {
        ListView()
        .tabItem {
            Image(systemName: "list.dash")
            Text("List")
        }

将ListView包裹在NavigationView中修复了崩溃问题。
我在 Caleb Wells <的 Swift Live – 007 SwiftUI TabView& List上看到了NavigationView的这种用法/ a>。
https://youtu.be/v1A1H1cQowI

Wrapping the ListView in a NavigationView fixed the crash. I saw this use of NavigationView on "Swift Live – 007 SwiftUI TabView && List" by Caleb Wells. https://youtu.be/v1A1H1cQowI

https:// github.com/calebrwells/A-Swiftly-Tilting-Planet/tree/master/2019/Live%20Streams/TabView%20List

这有效:

var body: some View {
    TabView {
        NavigationView { ListView() }
        .tabItem {
            Image(systemName: "list.dash")
            Text("List")
        }

这篇关于如何调试“前提条件失败”?在Xcode中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆