I have a problem with a MacCatalyst app I build and run on MacOS 14.6 with XCode 16.4. The problem doesn't occur on MacOS 13.6 or iOS 16 or 17. In this app if I click a button to show a .sheet(item a few times (typically between 3 and 8 times) then the app starts consuming 100% CPU and the Spinning Wait Cursor shows. The cause of the issue is that my NavigationSplitView has a ZStack so that state is maintained for all panels, as recommended here1 and here2. Minimum reproducible example is below. I would appreciate any suggestions on how to address this. This app must support iOS 16 and MacOS 13.6 as well. Thank you!
import SwiftUI
enum Panel: Hashable {
case panel
}
@main
struct MyApp: App {
@State private var selection: Panel? = Panel.panel
var body: some Scene {
WindowGroup {
NavigationSplitView {
List(selection: $selection) {
NavigationLink(value: Panel.panel) {
Label("Panel", systemImage: "circle")
}
}
} detail: {
ZStack { // this causes a crash on MacOS 14.6, but is required to maintain state on 13.6
ContentView()
}
}
}
}
}
struct PopupItem: Identifiable {
let id = UUID()
}
struct ContentView: View {
@State var popupItem : PopupItem?
var body: some View {
Button {
popupItem = PopupItem()
} label: {
Text("Show popup")
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.navigationBarTitleDisplayMode(.inline)
.sheet(item: $popupItem) { popupItem in
DismissView()
}
}
}
struct DismissView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
Button {
dismiss()
} label: {
Text("Dismiss")
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Text("Popup")
}
}
}
}
}
Post
Replies
Boosts
Views
Activity
When Swiftui Self._printChanges() prints StructName: @self changed. How do I determine why self changed?
When Swiftui Self._printChanges() prints StructName: @40 changed. what does the 40 represent ?