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?
}