Xcode 15 beta 5 issue when using @Query data to update Button label

I'm getting this error:

Abnormal number of gesture recognizer dependencies: 700. System performance may be affected. Please investigate reducing gesture recognizers and/or their dependencies.

It's caused by a view that loads a project and queries a favorite model for a project. I use this data to determine which system image to show.

Here's my model:

import Foundation import SwiftData

@Model final class FavoriteModel { @Attribute(.unique) var id: UUID = UUID() @Attribute var createdDate: Date @Relationship var project: Project

init(createdDate: Date = .now) {
    self.createdDate = createdDate
}

}

Here's the init for my view:

@Query var favorites: [FavoriteModel]

init(project: Project?) {
    self.project = project
    
    guard let projectID = project?.id else { return }
    
    let filter = #Predicate<FavoriteModel> {
        $0.project.id == projectID
    }
    
    _favorites = Query(filter: filter, sort: \FavoriteModel.createdDate)
}

Here's the code that is responsible for the error:

    Button {
        //favorite
    } label: {
        if favorites.isEmpty {
            Image(systemName: "heart")
        } else {
            Image(systemName: "heart.fill")
        }
    }

If I remove "favorite.isEmpty", the error disappears when I press the button. This use to work in Xcode 15 beta 4.

Is anyone else seeing this? It looks like a bug, but there's also probably a better solution.

Thanks,

Post not yet marked as solved Up vote post of jtressle Down vote post of jtressle
1.7k views

Replies

when I stopped working yesterday, I was at the same point.

I removed the predicate and no longer had infinite updates due to “@depdencies changed.” (printed to the console via let _ = Self._printChanges() in the View’s body. That means the query is wrong but there is no data in the db yet in my case so it’s an empty result regardless.

I haven’t been able to get back to that project yet today.

I'm seeing a related issue in my app as well. I also have a query that I overwrite a view init similar to your

_favorites = Query(filter: filter, sort: \FavoriteModel.createdDate)

However, very strangely, I have an interaction with my TabView navigation. I have a navigator class

@Observable
public final class Navigator {
    public var route: Route? = nil
}

and my tabview binds to it

            TabView(selection: $navigator.route) {
                Text("view 1")
                    .tabItem { Label("Recent", systemImage: "chart.bar.xaxis") }
                    .tag(Route.locationDetail as Route?)
                
            }

If I instead get rid of the Navigator, and just bind to a local @State var route: Route in the view, then it eliminates the problem in one app. In another app we've got IP, we just have to comment out the = Query(...) change in the view initializer (thereby breaking the view)

I ended up getting something to work by removing:

@Query var favorites: [FavoriteModel]

and adding a favorites relationship to my project model:

@Relationship(.cascade) var favorite: FavoriteModel? = nil

Just extra bookkeeping when I favorite a project, but it probably was the correct way to implement this.