Hello guys,
I am following along the CodeHistory app and on one of the last stages they ask to set a background modifier at the end of a ZStack to include a NavigationLink to the GameOver view.
Unfortunately the NavigationLink used is now deprecated on iOS 16 devices and this makes the project to not compile.
See below pictures:
Any idea on how to get around this?
4 Likes
I’m having a similar issue while building the the store app in the Navigation section of the course. Any recommendations?

Same issue here!
The course is outdated 
Solved it like this:
//
// ContentView.swift
// Ligaya Store
//
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
Text("Items in stock")
.font(.title)
.padding()
Spacer()
NavigationLink("Shrimp Chips") { ItemDetailView(itemName: "Shrimp Chips") }
Spacer()
}
.padding()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
//
// ItemDetailView.swift
// Ligaya Store
//
import SwiftUI
struct ItemDetailView: View {
@State var quantityRemaining = Int.random(in: 1...5)
@State var isCartEmpty = false
let itemName: String
var body: some View {
NavigationStack {
VStack {
Text("\(itemName)")
.font(.title)
.padding()
Spacer()
Image(systemName: "photo")
.font(.system(size: 200))
.padding()
Text("Quantity Remaining: \(quantityRemaining)")
Spacer()
Button {
if quantityRemaining > 0 {
quantityRemaining -= 1
if quantityRemaining == 0 {
isCartEmpty = true
}
}
print("Remaining quantity: \(quantityRemaining)")
} label: {
Text("Add one to your cart")
}
Spacer()
}
.navigationDestination(isPresented: $isCartEmpty) {
Text("You bought all the \(itemName)!")
}
} }
}
struct ItemDetailView_Previews: PreviewProvider {
static var previews: some View {
ItemDetailView(itemName: "Test Item")
}
}
I still don’t get why I get no animation between the cart and the empty cart text.
Update the course 
2 Likes
You’re getting this because iOS 16 switched to using NavigationStack instead of NavigationView. To fix this simply change your minimum deployment target to iOS 15 or 14.
If you click on your main project folder in the navigator panel this will open up the project settings. Under general, you’ll see a “Minimum Deployments” section. You can set this to 15 or 14 or anything lower than targeting only those iOS versions that are running 16+. This is normal as most apps support devices that are running older versions anyways because they don’t want to exclude users on older OS’s.
I hope this helps.
Same here, fixed by changing the minimum deployment targets. Hopefully they can update the course to avoid confusion.
Thanks! It helped me to unstuck!
I think I figured a way to get around this cause my coded finally worked for going to a new page without the use of a button.
class Coordinator: ObservableObject{
~Published var path = NavigationPath()
func show<V>(_ viewType: V.Type) where V: View{
path.append(String(describing: viewType.self))
}
func popToRoot(){
path.removeLast(path.count)
}
}
struct noItemView: View{
let itemName: String
var body: some View{
VStack{
Text("There are no more \(itemName) remaining.")
}
}
}
struct ItemDetailView: View {
~State var quantityRemaining = Int.random(in: 1…10)
~StateObject private var coord = Coordinator()
let itemName: String
var body: some View {
NavigationStack(path: $coord.path){
VStack{
Text(itemName).font(.largeTitle).padding()
Spacer()
Image(systemName: "photo").font(.system(size: 200)).padding()
Text("Quantity Remaining: \(quantityRemaining)")
Spacer()
Button(action: {
if quantityRemaining > 0{
quantityRemaining -= 1
if quantityRemaining == 0{
coord.show(noItemView.self)
}
}
}, label: {
Text("Add to Cart")
})
Spacer()
}.navigationDestination(for: String.self){ id in
if id == String(describing: noItemView.self){
noItemView(itemName: itemName)
}
}
}
.environmentObject(coord)
}
}
Where I put a “~” is actually a “@” cause the forums would not let me put too many @s. The link below is what helped me with my code if you guys need a breakdown of it.
the solution to this problem is simple, there is a different navigation link you can use instead of the deprecated one.
this is the one you can use, the different between it and the deprecated one is the data type of the destination.
1 Like