Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SIGABRT: Precondition failure: imported node deleted before its value was read

Tags:

ios

swift

swiftui

Since the beta 5 of Xcode 11 launched, I have had to update the code. You know the drill. However, there is this weird runtime error that is surviving the changes, and I cannot figure out why it happens.

I started trying to corner it within my original code, but surprisingly it also happens in the simplest test project that I managed to come up with: a TabView with a table.

The procedure to have the Xs simulator crash with SIGABRT while changing to another tab in runtime with the error:

"xxxxxxx[23089:4642999] precondition failure: imported node deleted before its value was read: 90"

If the user enters the detailview clicking in a row, it does not crash; just run the app and press the second tab.

I have revised the view building, the object ... nothing. It even crashes when changing the row view to a simple Text. I also removed @Binding , etc. to rule out Combine.

Please, let me know if any of you guys see something. It only crashes in Beta 5, not in Beta 2.

//  This file can be used in a new TabView app in Xcode 11 beta 5
//  ContentView.swift


import SwiftUI


class TestObject : Identifiable, Hashable{

    let identifier: String


    init() {
        self.identifier = UUID().description
    }

    static func == (lhs: TestObject, rhs: TestObject) -> Bool {
        return lhs.identifier == rhs.identifier
    }

    func hash(into hasher: inout Hasher) {
        hasher.combine(identifier)
    }

}

struct RowView: View {
    let aTitle: String
    var body: some View {
        HStack {
            Spacer()
            Text(aTitle)
            Spacer()
        }
    }
}

struct DetailView: View {
    let aObject: TestObject
    var body: some View {
        VStack {
            Spacer()
            Text(aObject.identifier)
            Spacer()
        }
    }

}


struct ListNavegableNoBinding: View {
    var testObjects: [TestObject]
    var body: some View {
        NavigationView {
            List(testObjects, id: \.self) {
                someObject in
                NavigationLink(destination: DetailView(aObject: someObject)) {
                    RowView(aTitle: someObject.identifier)
                }
            }

        }
    }
}

struct ContentView: View {
    @State private var selection = 0

    var tests : [TestObject] = [
        TestObject(),
        TestObject(),
        TestObject()
    ]


    var body: some View {
        TabView(selection: $selection){

            VStack{
                Text("First View")
                    .font(.title)
                ListNavegableNoBinding(testObjects: tests)
            }
            .tabItem {
                VStack {
                    Image("first")
                    Text("First")
                }
            }
            .tag(0)

            Text("Second View")
                .font(.title)

                .tabItem {
                    VStack {
                        Image("second")
                        Text("Second")
                    }
            }
            .tag(1)

        }
    }
}

like image 427
jpelayo Avatar asked Aug 01 '19 07:08

jpelayo


3 Answers

I still have this issue on Xcode 11.0 (11A420a). The crash happens only when NavigationLink used inside a dynamic List. the only work around for me was to use a ForEach inside the List like below:

List {
    ForEach(store.items, id: \.id){ item in
        NavigationLink(destination: YourDefinitionView()) {
            Text("some text")

        }

    }
}
like image 146
alizx Avatar answered Nov 01 '22 20:11

alizx


Xcode Beta 5 is really a step backward in terms of quality. My project is totally broken. First, the known issue with crashing Shape and also with the Tab and List views.

I have the following code which doesn't work anymore. It crashes on selecting the seconds tab:

struct WorkoutList: View {
    var workoutCollection: WorkoutCollection

    var body: some View {
        NavigationView {
            List(workoutCollection.workouts) { workout in
                NavigationLink(destination: WorkoutDetail(workout: workout)) {
                    WorkoutRow(workout: workout)
                }.accessibility(identifier: "workout")
            }.accessibility(identifier: "workoutList").navigationBarTitle(Text("workouts.title"))
        }
    }
}

When replacing the dynamic List with a static one it works without any issues:

struct WorkoutList: View {
    var workoutCollection: WorkoutCollection

    var body: some View {
        NavigationView {
            List() {
                NavigationLink(destination: WorkoutDetail(workout: workoutCollection.workout[0])) {
                    WorkoutRow(workout: workoutCollection.workout[0])
                }.accessibility(identifier: "workout")
            }.accessibility(identifier: "workoutList").navigationBarTitle(Text("workouts.title"))
        }
    }
}

I think we have to wait for Beta 6.

like image 2
G. Marc Avatar answered Nov 01 '22 19:11

G. Marc


With Xcode Beta 6 (just released yesterday), my TabViews are working properly again. No more SIGABRT errors. So, time to upgrade!

like image 1
KB-YYZ Avatar answered Nov 01 '22 18:11

KB-YYZ