Since updating to Xcode Beta 6 earlier today my application will no longer build, it was working fine in Beta 5 and earlier.
This is the code from the file with the error message, although I'm aware at the moment this doesn't necessarily mean this is where the error actually lies.
import SwiftUI
struct JobView_Table : View {
@ObservedObject var jobList: JobDetailViewModel = JobDetailViewModel()
var body: some View {
NavigationView {
List {
ForEach($jobList.jobDetails) { job in
NavigationLink(destination: JobDetailHost(jobDetails: job)) { // ERROR: "Type of expression is ambiguous without more context"
JobView_List(jobDetails: job)
}
}
}
.navigationBarTitle(Text("My Jobs"))
.onAppear(perform: fetchData)
.onAppear(perform: {
print("Hello!")
})
}
}
private func fetchData() {
return(jobList.updateDetails())
}
}
The struct containing the data conforms correctly to the following protocols.
struct JobDetails: Codable, Identifiable, Equatable, Hashable {
...
...
}
This is the class which provides the data to JobView_Table
.
import Foundation
import UIKit
import Combine
class JobDetailViewModel: ObservableObject, Identifiable {
@Published var jobDetails: [JobDetails] = []
func updateDetails() {
self.jobDetails = DataManager().fetchJobList()
}
}
And finally the target view which is linked to via the NavigationLink
.
struct JobDetailHost: View {
@Environment(.editMode) var mode
@Binding var jobDetails: JobDetails
var body: some View {
VStack {
JobDetailView(jobDetails: jobDetails)
}
.navigationBarItems(trailing: EditButton())
}
}
I notice that some others seem to be having similar problems, i.e. in the two questions listed below, but exploring the answers in these questions is not helping me at this moment.
SwiftUI Xcode 11 beta 5 / 6: Type of expression is ambiguous without more context
SwiftUI: Why does ForEach($strings) (text: Binding) not build?
EDIT:
I have tried implementing the suggestion from Fabian, this has got rid of the error, however no content is being populated in the list.
This is the adjusted List
code, which compiles successfully but when running the application the list is not populated.
List {
ForEach(jobList.jobDetails.indexed(), id: .1.id) { (index, job) in
NavigationLink(destination: JobDetailHost(jobDetails: self.$jobList.jobDetails[index])) {
Text(job.jobName)
}
}
}
The following does not use the ForEach
and discards the NavigationLink
, and still doesn't work.
List(jobList.jobDetails.indexed(), id: .1.id) { (index, job) in
Text(job.jobName)
}
See Question&Answers more detail:
os