Problem
I got an error message "Cannot convert value of type '[Properties]' to expected argument type 'Binding" while using ForEach
ScrollView {
LazyVStack(alignment: .center) {
ForEach(foodFilterResult[currentIndex], id: \.self) { // (Error occurred here)
value in
NavigationLink {
FoodInfoView(foodInfo: modelData.foodData.filter{$0.name.title.first!.text.content == value}.first!)
} label: {
ZStack{
RoundedRectangle(cornerRadius: 15)
.foregroundColor(.orange).opacity(0.06)
.frame(width: 350, height: 280)
VStack(alignment: .leading) {
Text("\(value)")
.foregroundColor(.black)
.padding(.bottom, -3)
.font(.system(size: 20).weight(.heavy))
.frame(width: 300, alignment: .leading)
More Information
The foodFilterResult[currentIndex] (which is the data used in ForEach) has a type [Properties]
var foodFilterResult = foodFilter()
func foodFilter () -> [[Properties]] {
var western : [Properties] = []
var korean : [Properties] = []
var chinese : [Properties] = []
var japanese : [Properties] = []
var asian : [Properties] = []
var cafe : [Properties] = []
...
}
return [korean, western, chinese, japanese, asian, cafe]
}
Properties
The struct "Properties" is a DTO for getting data from Notion DataBase
struct Properties: Codable, Equatable {
let imageFile: ImageFile
var id: IDClass
let propertiesDescription: Description
let transportation: People
let location, imageName: Description
let category, price: Category
let people: People
let name: Name
var isFavorite = false
enum CodingKeys: String, CodingKey {
case imageFile, id
case propertiesDescription = "description"
case transportation, location, imageName, category, price, people, name
}
}
Tries
I firstly searched ForEach and found that Data used in ForEach need toconform to RandomAccessCollection. But I don't know how to adjust it.
Can anybody help how to solve or access this kind of problem?