Specifically I have one separate view:
import SwiftUI
struct AllGoalsView: View {
let goals: [Goal]
let markGoalAsAchieved: (Goal) -> Void
var body: some View {
if goals.isEmpty {
Text("No goals available or still loading...")
.foregroundColor(.gray)
.italic()
.navigationTitle("Performance Targets")
.navigationBarTitleDisplayMode(.inline)
} else {
List(goals, id: \.id) { goal in
GoalRow(goal: goal, markGoalAsAchieved: markGoalAsAchieved)
}
.navigationTitle("Performance Targets")
.navigationBarTitleDisplayMode(.inline)
.listStyle(.plain)
}
}
}
struct GoalRow: View {
let goal: Goal
let markGoalAsAchieved: (Goal) -> Void
var body: some View {
HStack {
VStack(alignment: .leading) {
if let lift = goal.lift {
Text(lift.liftName)
.fontWeight(.regular)
} else {
Text("Unknown Lift")
.fontWeight(.regular)
}
Text("\(goal.targetValue, specifier: "%.2f") kg")
.font(.subheadline)
.fontWeight(.medium)
.foregroundColor(.accentColor)
}
Spacer()
if goal.achieved {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
}
}
.swipeActions(edge: .trailing) {
if !goal.achieved {
Button("Achieved") {
markGoalAsAchieved(goal)
}
.tint(.green)
}
}
}
}
and in parent view I have declaration @State and call it with NavigationLink:
@State var goals: [Goal] = []
...
VStack(alignment: .leading) {
if !goals.isEmpty {
NavigationLink(
destination: AllGoalsView(goals: goals, markGoalAsAchieved: markGoalAsAchieved)
) {
HStack {
Text("Your Goals")
.font(.headline)
Image(systemName: "chevron.right")
.font(.headline)
Spacer()
}
.foregroundColor(.primary)
}
.padding(.leading, 20)
.padding(.top, 10)
}
}
I get:
Generic parameter 'Data' could not be inferred
Cannot convert value of type '[Goal]' to expected argument type 'Binding'
This is error that appears completely randomly but app still builds and runs (and functions properly) and then error disappears.
I tried everything I can think of. My view has lots of fetches from API for database, but this happens when I'm using AllGoalsView, if I remove it then it's cleared. Can you see anything off with this specific code?