I've got a protocol with two classes that implement it:
protocol GalleryItem {
func toView() -> AnyView
}
extension Class1:GalleryItem {
func toView() -> AnyView {
...
}
}
extension Class2:GalleryItem {
func toView() -> AnyView {
...
}
}
An array:
var array:[GalleryItem] = [Class1(), Class2()]
Now if I try to use that array in a ForEach:
ForEach(array, id: \.self) { item in
item.toView()
}
I get this error:
Value of protocol type 'GalleryItem' cannot conform to 'Hashable'; only struct/enum/class types can conform to protocols
Does that mean I can't have a protocol array like this passed to ForEach? How else would I accomplish this?