Not getting this type-inference issue

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?

It's a long standing Xcode bug where diagnostics show up in the middle of the build process but then are never cleaned up. Annoyingly, Xcode also caches the diagnostics so you'll have to quit and clear your derived data for it to truly go away.

(Seriously, they even called out in the Xcode 16 release notes that this issue had been fixed, but it seems even worse now.)

1 Like

Oh. Thats one thing I was hoping for, and on the other hand I made a mess out of my code trying to avoid it even though app worked perfectly :face_with_diagonal_mouth:

I thought clean build would fix it if it was some weird xcode issue but because it was pointing to my specific view when it happened, I was trying to fix it or thought of giving up of having that view.

This makes sense then, perhaps its time to even upgrade Xcode now. Thanks