As you can find in the error message, each element passed to ForEach needs to conform to Identifiable (or easily provide id to identify).
You should better think Image is not a good thing to hold in an Array and use with ForEach.
One possible solutions would be holding UIImage (or CGImage) in an Array:
Something like this:
struct FilterView: View{
@State var image: Image?
let filteredUIImage: [UIImage] //<-
var body: some View {
NavigationView{
ZStack{
//...
VStack {
//...
ScrollView(.horizontal, showsIndicators: false) {
HStack{
ForEach(filteredUIImage, id: \.self) { uiImage in //<-
//...
}
}
}
}
}
}
.toolbar {
//...
}
}
//...
}
And creating a local variable holding a view does not make sense.
You need to update your loadFilter():
struct ContentView: View {
//...
@State var filteredUIImage: [UIImage] = [] //<-
//...
var body: some View {
//...
.navigate(to: FilterView(image: image, filteredUIImage: filteredUIImage), when: $showingFilterView) //<-
}
//...
func loadFilter() {
filteredUIImage = []
filters.forEach { (filters) in
//...
let uiImage = UIImage(cgImage: cgimg!)
//let filteredImage = Image(uiImage: uiImage)
//Creating a view as local variable does not make sense
// let filterView = FilterView()
// filterView.filteredImage.append(filteredImage)
filteredUIImage.append(uiImage)
}
}
}
I'm not sure if this is the best solution for your purpose, generally having many images in an array would not be recommended.