The use of NavigationView has been deprecated.
Apple states:
If your app has a minimum deployment target of iOS 16, iPadOS 16, macOS 13, tvOS 16, or watchOS 9, or later, transition away from using NavigationView. In its place, use NavigationStack and NavigationSplitView instances.
Try your code with NavigationStack instead.
import SwiftUI
struct MainView: View {
@State var showingAlert = false
var body: some View {
NavigationStack {
Button( "Tap me") {
showingAlert = true
}
.navigationTitle("Title")
.toolbar {
Label("bell", systemImage: "bell")
}
}
.alert("Alert", isPresented: $showingAlert) {
Button("OK", role: .destructive) { }
}
}
}
struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: