This app will not crash when switching between these two tabs with TabView init(content:)
import SwiftUI
import SwiftData
struct ContentView: View {
@StateObject private var highlightManager = HighlightManager.shared
@State private var selectedTab: Int = 0
var body: some View {
TabView(selection: $selectedTab) {
MapView()
.tabItem {
Label("Map", systemImage: "map")
}
.tag(0)
// Annotation Tab
AnnotationList()
.tabItem {
Label("Annotation", systemImage: "mappin.and.ellipse")
}
.tag(1)
// Group Tab
PeopleList()
.tabItem {
Label("Group", systemImage: "person.and.person")
}
.tag(2)
}
.tutorialOverlay() // Apply the overlay to the root view
.environmentObject(highlightManager)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
NavigationLink("Help") {
NavigationStack {
HelpView(selectedTab: selectedTab)
}
}
}
}
}
}