问题
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)
}
}
}
回答1:
With Xcode Beta 6 (just released yesterday), my TabViews are working properly again. No more SIGABRT errors. So, time to upgrade!
回答2:
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")
}
}
}
回答3:
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.
回答4:
I have a TabView with a list inside every tab, and my app is totally broken now. It seems like it has trouble dereferencing the List component. We'll have to wait, but I hope for a hotfix to release very soon.
回答5:
Similar situation here. Instead of using a List however, I am using Form and that seems to cause this error when ever I tap from that Tab to any other tab or vice versa. Weird, weird stuff.
回答6:
I still have this issue on Xcode 11 GM... I have three tabs all with lists inside, and whenever I change tabs while scrolling the current view the SIGBART crash occurs.
来源:https://stackoverflow.com/questions/57303951/sigabrt-precondition-failure-imported-node-deleted-before-its-value-was-read