‘init(destination:isActive:label:)’ was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a NavigationStack or NavigationSplitView’
2 min readSep 15
--
Me to solved this warning:
If you are using iOS 16 which is causing the warning to occur. the first step you have to use is NavigationStack on each display. I will show how to fix it below:
ContentView ( use NavigationStack on each display) :
import SwiftUI
struct ContentView: View {
@State private var isPageone = false
@State private var isPagetwo = false
var body: some View {
\\ important to useNavigationStack
NavigationStack{
VStack{
Text("Learn Swift UI With Naufal")
HStack{
Image(systemName: "swift")
.resizable()
.foregroundColor(Color.blue)
.frame(width: 60, height: 60)
}
.padding(.top,30)
Button(action: { isPageone = true }, label: {
Text("Button Page 1")
.foregroundColor(Color.white)
.padding(.vertical,8)
.padding(.horizontal,15)
.background(Color("color-blue"))
.cornerRadius(30)
.shadow(color: Color.black.opacity(0.07), radius: 40, x: 0, y: 5)
.padding(.top,60)
})
.navigationDestination(
isPresented: $isPageone) {
PageOne()
Text("")
.hidden()
}
Button(action: { isPagetwo = true }, label: {
Text("Button Page 2")
.foregroundColor(Color.white)
.padding(.vertical,8)
.padding(.horizontal,15)
.background(Color("color-blue"))
.cornerRadius(30)
.shadow(color: Color.black.opacity(0.07), radius: 40, x: 0, y: 5)
.padding(.top,10)
})
.navigationDestination(
isPresented: $isPagetwo) {
PageTwo()
Text("")
.hidden()
}
}
}
}
}
Button View:
struct PageOne: View {
var body: some View {
NavigationStack{
VStack{
Text("View Page 1")
}
}
}
}
struct PageTwo: View {
var body: some View {
NavigationStack{
VStack{
Text("View Page 2")
}
}
}
}
Thanks for reading!. Stay tuned for more SwiftUI articles by Naufal Adli which will be coming soon and dont forget to like and follow.this artikel make Hand-crafted & Made with❤️.