List with selection: SelectionManagerBox<UUID> tried to update multiple times per frame.

Hi, first time posting here (sorry if it's a bit long).

I'm using MacBook Pro 16-inch 2021 (M1), macOS 14.5, Xcode 15.4.

I'm somewhat new to SwiftUI + SwiftData, as my macOS development experience is from (way too) many years ago.

I'm developing a SwiftData application, which (so far) is going fairly smoothly. I've reduced my application code to a minimum by commenting out most of it, and I still see the same error message.

I've poked around the Internet for a while now, looking for any hints, but nothing seems to address this specific issue (most talk about other views/types, and in some of those cases the problem is readily apparent).

Here's the (reduced) code for the view in question (it's the primary view in a single-window app; I've barely started so there's not much else there):

// Model/Config.swift

@Model
final class Config: Identifiable {
    @Attribute(.unique)
    var uuid: UUID = UUID()

    // ...

    var id: UUID { // for the Identifiable protocol
        uuid
    }
}

// Views/ContentView.swift

struct ContentView: View {
    @Environment(\.modelContext) private var modelContext
    @Query private var items: [Config]
    @State private var theSelection: Config.ID?

    var body: some View {
        NavigationSplitView {
            List(items, selection: $theSelection) { item in
                NavigationLink {
                    Text("UUID: \(item.uuid)")
                } label: {
                    Text(item.uuid.uuidString)
                        .font(.title2)
                }
            }
        } detail: {
            Text("Select an item")
        }
    }
}

Initially when I run the app, no (existing) items are selected. When I click to choose one of the items (doesn't matter which one), I get the error message from the post title, which I'll repeat here:

List with selection: SelectionManagerBox<UUID> tried to update multiple times per frame.

It only appears the one time. My item deletion code (not shown above) resets theSelection = nil (by the time I get to this code, the problem has already occurred, so it can't be this). Clicking to make a subsequent selection does not trigger the message again.

Other than this message, the view seems to be operating as expected.

I also tried:

  • remove selection from List()
    • problem goes away
  • change selection type to UUID? and List(id: \.uuid), remove Identifiable and id from Config
    • problem persists
  • change selection type to Config? and List(id: \.self)
    • problem persists
  • change the List to have just the selection, and use ForEach to build the items' views
    • problem persists

I do see other messages (which other posts indicate are likely noise), but those are typically coloured yellow ("warning"?). The message I'm posting about is shown in red/purple ("error?").

I'm not too worried for now given that the view seems to be behaving OK otherwise, but my concern is whether this will come back to bite me down the road.

Thanks for your time and attention.

I was unable to reproduce the issue on my end. See Creating a test project and share a link to a test project. I'd be happy to take a look. Thanks

Hi @DTS Engineer, thanks for responding.

The page you pointed me to claims that The forums have a list of websites you can link to, but I have yet to find this.

I have successfully reproduced the issue using the following steps:

  1. Create a SwiftData app
    • File...New...Project -> macOS...App...Next -> SwiftData
    • I called mine IssueTest
  2. Edit Item.swift:
    • add the Identifiable protocol
    • add a property var id = UUID()
  3. Edit ContentView.swift:
    • add @State private var selection: Item.ID?
    • add selection to List: List(selection: $selection)
  4. Run the app and do:
    • click on the '+' to add one or more entries
    • click on any of the list items
    • the message should appear immediately

Here is the (git) diff from the project's auto-generated repo:

diff --git a/IssueTest/ContentView.swift b/IssueTest/ContentView.swift
index 0141127..e369ee2 100644
--- a/IssueTest/ContentView.swift
+++ b/IssueTest/ContentView.swift
@@ -11,10 +11,11 @@ import SwiftData
 struct ContentView: View {
     @Environment(\.modelContext) private var modelContext
     @Query private var items: [Item]
+    @State private var selection: Item.ID?

     var body: some View {
         NavigationSplitView {
-            List {
+            List(selection: $selection) {
                 ForEach(items) { item in
                     NavigationLink {
                         Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
diff --git a/IssueTest/Item.swift b/IssueTest/Item.swift
index d06b484..fba89db 100644
--- a/IssueTest/Item.swift
+++ b/IssueTest/Item.swift
@@ -9,7 +9,8 @@ import Foundation
 import SwiftData

 @Model
-final class Item {
+final class Item: Identifiable {
+    var id = UUID()
     var timestamp: Date

     init(timestamp: Date) {

And here's a snapshot of the error:

BTW, I see the same error when running the Book Club sample (unmodified) from the Bringing multiple windows to your SwiftUI app page.

https://developer.apple.com/documentation/swiftui/bringing_multiple_windows_to_your_swiftui_app

@DTS Engineer

Hi, I created a minimal test project here to reproduce the issue.

Would really appreciate if you could take a look.

List with selection: SelectionManagerBox&lt;UUID&gt; tried to update multiple times per frame.
 
 
Q