TabItem Not Respected In TabView

Hello, I'm a new programmer here, so this may be an error on my part, however I have tried my best to research the issue and believe I may have discover a bug. I have a set of tabItems inside of a TabView using a variable to track the selected tab called selectedIndex. I have added in a text view to watch the selected tab. This works correctly in the canvas and in a simulator, however whenever I build this on an iOS Device or for my Mac the selectedIndex does not change when selecting tabs like it does in the canvas and simulator. Instead it just stays at the default 0. Any assistance would be great. :-)

import SwiftUI

struct ContentView: View {
    @State private var selectedIndex = 0
    
    var body: some View {
        Text("\(selectedIndex)")
        TabView(selection: $selectedIndex) {
            FilteredApplicantListView()
                .tabItem { Label("Applicant Processor", systemImage: "person.3.sequence.fill") }
                .tag(0)
            QuickFinancials()
                .tabItem { Label("Quick Financials", systemImage: "dollarsign.gauge.chart.leftthird.topthird.rightthird") }
                .tag(1)
            MoveInView()
                .tabItem { Label("Move Ins", systemImage: "figure.walk.arrival") }
                .tag(2)
            MoveOutView()
                .tabItem { Label("Move Outs", systemImage: "figure.walk.departure") }
                .tag(3)
        }
    }
}

I tested on a Mac macOS Sonoma 14.5, Xcode 16.0ß2.

I created dummy Views to call, but the does not matter.

struct FilteredApplicantListView: View {
    var body: some View {
        Text("FilteredApplicantListView")
    }
}

struct QuickFinancials: View {
    var body: some View {
        Text("QuickFinancials")
    }
}

struct MoveInView: View {
    var body: some View {
        Text("MoveInView")
    }
}

struct MoveOutView: View {
    var body: some View {
        Text("MoveOutView")
    }
}

It works, as shown below:

What is your configuration ?

Hi @erfinb, I see that @Claude31 tested this on Mac, and I tested it on iOS and get the same results as them.

Please let us know what Xcode version you're on and what iOS version you're targeting.

Try creating a new project that contains only this code and see if you get the same behavior.

import SwiftUI
struct ContentView: View {
    @State private var selectedIndex = 0
    
    var body: some View {
        Text("\(selectedIndex)")
        TabView(selection: $selectedIndex) {
            Text("1")
                .tabItem { Label("Applicant Processor", systemImage: "person.3.sequence.fill") }
                .tag(0)
            Text("2")
                .tabItem { Label("Quick Financials", systemImage: "dollarsign.gauge.chart.leftthird.topthird.rightthird") }
                .tag(1)
            Text("3")
                .tabItem { Label("Move Ins", systemImage: "figure.walk.arrival") }
                .tag(2)
            Text("4")
                .tabItem { Label("Move Outs", systemImage: "figure.walk.departure") }
                .tag(3)
        }
    }
}

The placeholder Text instead of your views can help simplify to debug.

TabItem Not Respected In TabView
 
 
Q