@Observable crashes in Xcode, iOS Beta 7 on iPad

If you update the code using @Observable, it works normally on macOS, but an error occurs on iPad.

Simultaneous accesses to 0x60000300c9a0, but modification requires exclusive access.

The first time I select it from the list, it works fine, but the second time I select it, an error occurs.

original source code

struct ContentView: View {
    
    @StateObject private var envProfile = ProfileEnvironment()
    
    var body: some View {
        NavigationSplitView {
            List(selection: $envProfile.selection) {
                NavigationLink("One", value: "1")
                NavigationLink("Two", value: "2")
            }
        } detail: {
            Text(envProfile.selection ?? "nil")
        }
    }
}

class ProfileEnvironment: ObservableObject {
    @Published var selection : String?
}

Updated code using @Observable

struct ContentView: View {
    
    @State private var envProfile = ProfileEnvironment()
    
    var body: some View {
        NavigationSplitView {
            List(selection: $envProfile.selection) {
                NavigationLink("One", value: "1")
                NavigationLink("Two", value: "2")
            }
        } detail: {
            Text(envProfile.selection ?? "nil")
        }
    }
}

@Observable
class ProfileEnvironment {
    var selection : String?
}

I checked and get the same error. The only issue I found with your code is that you declared the property with @State but you should have declared it with @Bindable. But I tried and keep getting the error. It has to be a bug. The only solution was to manage the selection from a @State property (@State private var envProfile: String?)

The problem was not resolved in XCode 15.0 beta 8.

@Observable is a very nice macro.

However, errors occur even in such simple code, so using @Observable is a very dangerous choice.

This is a known issue, and cited in the iOS 17 beta 8 release notes:

On iOS, using an Observable object’s property as a selection value of a List inside NavigationSplitView may cause a “Simultaneous accesses to …” error when a list selection is made via tap gesture. (113978783)

Workaround: There is no current workaround for Observable properties. Alternatives include factoring out the selection value into separate state stored outside the object, or using ObservableObject instead.

@Observable crashes in Xcode, iOS Beta 7 on iPad
 
 
Q