iOS 17b6: Simultaneous accesses to ..., but modification requires exclusive access crash using Observation and SwiftUI

Since iOS/iPadOS beta 6, I get a crash just by simply selecting an item in the sidebar of a navigation view. The selected item is part of an app mode, with conforms to the Observation protocol:

import SwiftUI
import Observation

@main
struct MREAApp: App {
    @State private var appModel = AppModel.shared
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environment(appModel)
        }
    }
}

@Observable class AppModel {
    static var shared = AppModel()
    
    var selectedFolder: Folder? = nil
}

struct Folder: Hashable, Identifiable {
    let id = UUID()
    let name: String
}

struct ContentView: View {
    @Environment(AppModel.self) private var appModel
    
    var folders = [Folder(name: "Recents"), Folder(name: "Deleted"), Folder(name: "Custom")]
    
    var body: some View {
        NavigationSplitView {
            SidebarView(appModel: appModel, folders: folders)
        } detail: {
            if let folder = appModel.selectedFolder {
                Text(folder.name)
            }
            else {
                Text("No selection")
            }
        }
    }
}


struct SidebarView: View {
    @Bindable var appModel: AppModel
    
    var folders: [Folder]
    
    var body: some View {
        List(selection: $appModel.selectedFolder) {
            ForEach(folders, id: \.self) { folder in
                NavigationLink(value: folder) {
                    Text(folder.name)
                }
            }
        }
    }
}

To reproduce the bug, just tap on one of the item.

Oddly enough, this works fine in the Simulator.

macOS 14 beta 5 is not affected either.

Apple folks: FB12981860

I’m still curious as to whether anyone has tried this on the now-released iOS 17.1?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

iOS 17b6: Simultaneous accesses to ..., but modification requires exclusive access crash using Observation and SwiftUI
 
 
Q