protocol MyProtocol: Identifiable {
associatedtype CustomView: View
var id: UUID { get set }
func myui() -> CustomView
}
struct A: MyProtocol {
var id: UUID = UUID()
func myui() -> some View {
Text("My A view")
}
}
struct B: MyProtocol {
var id: UUID = UUID()
func myui() -> some View {
Text("My B view")
}
}
struct ContentView: View {
let myObjs: [any MyProtocol] = [A(), B()]
var body: some View {
VStack {
ForEach(myObjs, id: \.id) { obj in
obj.myui() //Static method 'buildExpression' requires that 'Content' conform to 'AccessibilityRotorContent'
//AnyView(obj.myui()) -> this works
}
}
}
}
Why is this throwing a compiler error?
Static method 'buildExpression' requires that 'Content' conform to 'AccessibilityRotorContent'
Wrapping it in AnyView seems to do the trick, but I was wondering if it can be avoided in my case here.