There's something I don't really understand about the transition from NavigationView
to NavigationStack
for SwiftUI 4 and iOS 16.
I have 2 applications running on the App Store (targeting iOS 15 and above) and of course I'm using NavigationView
. This weekend, I was looking for a solution to have them ready for iOS 16 by replacing:
var body: some View {
NavigationView {
ScrollView { /* code here */ }
}
}
To something like this:
var body: some View {
if #available(iOS 16, *) {
NavigationStack {
} else {
NavigationView {
}
ScrollView { /* code here */ }
}
}
But finally, before doing so, I tried them with iOS 16 Beta and they're perfectly fine. I don't understand, I thought it would be total a mess but finally no. Do you have an explanation? Maybe, deprecated isn't what it should mean?
CodePudding user response:
NavigationView
is deprecated, not obsoleted. When a component becomes deprecated, it still can be used until Apple decides to obsolete it which will cause a crash when used. Although it's functional, you shouldn't use it.