I have a lot of different types of elements in an array, and I want them all to know how to understand how to render themselves... it's quite complex and I'm always adding new types - don't want to have to do shotgun surgery each time
but can't seem to work out the syntax for inheritance of a function with an opaque type return - if I do this:
class Element
{
func forDisplay() -> some View
{ fatalError("this function needs to be overridden")}
}
then try to override it
class TextElement : Element
{
...
override func forDisplay() -> some View
{ return Text( self.textValue ) };
}
It gives me a compile error - and if I just leave out the word override
class TextElement : Element
{
...
func forDisplay() -> some View
{ return Text( self.textValue ) };
}
it compiles fine, runs fine - but then calls the underlying error function
Elementshould be a Protocol that the others adopt.forDisplaywould return that associated type.