Posts

Post not yet marked as solved
2 Replies
Compiler gives error because it expects to return opaque (only one) type of view.You may want to use AnyView. It will return the same view which you have created. But it might be costly operation. So you can wrap every thing under Group. This will be best option for you. But You can choose either way to come out of compile error.Option 1.func formattedView(_ tableType: TableType) -> some View { List { if tableType == TableType.oneType { return AnyView(OneTypeTableFormattedView(table)) } else if tableType == TableType.anotherType { return AnyView(AnotherTypeTableFormattedView(table)) } else { return AnyView(Text("No formatted view for \(tableType) table")) } } }}Option 2.func formattedView(_ tableType: TableType) -> some View { Group { List { if tableType == TableType.oneType { return OneTypeTableFormattedView(table) } else if tableType == TableType.anotherType { return AnotherTypeTableFormattedView(table) } else { return Text("No formatted view for \(tableType) table") } } } }}