Hi, As you can see in the code below whenever I open the app in the normal mode app works fine and the detail view shows data properly. However, in split screen the app lost data of the selected item. I'm sure there is a bug in here unless I should manage it by myself which unacceptable!
@main
struct TestSwiftUIApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct Employee: Identifiable {
let name: String
let id: Int
}
struct ContentView: View {
@State
var selectedEmployeeId: Employee.ID?
let employess: [Employee] = [.init(name: "Hamed", id: 1), .init(name: "John", id: 2)]
var body: some View {
NavigationSplitView {
List(employess, selection: $selectedEmployeeId) { employee in
Text(employee.name)
}
} detail: {
NavigationStack {
if let employee = employess.first{$0.id == selectedEmployeeId} {
EmployeeDetails(employee: employee)
}
}
}
}
}
struct EmployeeDetails: View {
let employee: Employee
var body: some View {
Text("Detail of empolyee\(employee.name) with id: \(employee.id)")
}
}