SwiftUI crash: AttributeGraph precondition failure

My app crashes and Xcode shows no stack trace. It just pops up some line of assembly language in __pthread_kill, and shows this in the console:

[error] precondition failure: invalid value type for attribute: 230424 (saw PreferenceKeys, expected ViewList) AttributeGraph precondition failure: invalid value type for attribute: 230424 (saw PreferenceKeys, expected ViewList).

Seems like a bug in SwiftUI. Any ideas? This is on macOS 11.
Same here. Happens when the user is scrolling a list quickly. Code is very simple:

Code Block Swift
...
List {
ForEach(filteredThings, id: \.self) { item in
itemRow(item: item, matched: $matched)
}
}
...


Had the same problem, just added .id(UUID()) as list modifier to disable animation and fix my issue.

This worked for me:
Code Block ...
List {
ForEach(filteredThings, id: \.self) { item in
itemRow(item: item, matched: $matched)
}
}.id(UUID())
...


I had the same problem, but when deleting +3 items quickly from a list. Following Ciurica's suggestion resolved it for me.

Same happens to me with a LazyVGrid, when I add and remove array items repeatedly (doesn't have to be fast), but only when using withAnimation. My use case is a "See All" / "Show Less" toggle.

In the button action:

withAnimation(.easeInOut(duration: 0.3)) { showAll.toggle() }

Without withAnimation I can toggle 100 times and still no crash.

Hi, I experienced this horrible problem and in my case was when using TabView.

I have TabView in my ContentView and then one of the List views inside had a NavigationView At the beginning I thought it was something wrong with my code cos was working previously. But after struggling a while. I moved the NavigationView to wrap the whole TabView and that fixed the issue.

So I will write here both examples the Non working one and the fix I did in case that might help others.

Problematic Code

struct ContentView: View {

    @EnvironmentObject var dataModel: DataModel

    var body: some View {
      TabView {
                LibraryList()
                    .tabItem {
                        Label(L10n.library, systemImage: Images.System.library)
                    }
                SettingsList()
                    .tabItem {
                        Label(L10n.more, systemImage: Images.System.more )

                    }
            }
    }
}

struct LibraryList: View {

    @EnvironmentObject var dataModel: DataModel

    var body: some View {
         NavigationView { // This navigation here seems to be the issue
               List(dataModel.books) { book in
                       NavigationLink(destination: Text("Book")) { // The crash seems to complain here.
                               Text("Book name: \(book.name)")
                      }
              }
        }
   }
}


The working solution

struct ContentView: View {

    @EnvironmentObject var dataModel: DataModel

    var body: some View {
          NavigationView { // Moved navigation view before TabView.
                TabView {
                       LibraryList()
                              .tabItem {
                                       Label(L10n.library, systemImage: Images.System.library)
                                }
                        SettingsList()
                               .tabItem {
                                       Label(L10n.more, systemImage: Images.System.more )
                                 } 
                    }
           }
    }
}

struct LibraryList: View {

    @EnvironmentObject var dataModel: DataModel

    var body: some View { 
               List(dataModel.books) { book in
                       NavigationLink(destination: Text("Book")) { // The crash seems to complain here.
                               Text("Book name: \(book.name)")
                      }
              }
     }
}

I hope this helps some of you.

The above solutions didn't work for me, but I figured it out. I had a code that nests ForEach inside LazyVStack inside ScrollView inside NavigationView inside TabView.

Quickly scrolling the list would result in:

AttributeGraph precondition failure: setting value during update: 2232

Simple exchanging the order of NavigationView and TabView did not work for me. What I did was to add .id(UUID()) to each tab views:

TabView {
    MyView()
        .id(UUID())
        .tabItem {

I didn't have to swap NavigationView and TabView nesting order.

It worked!

I had a NavigationView inside a NavigationView, removing the it from the child fixed it.

SwiftUI crash: AttributeGraph precondition failure
 
 
Q