I am working on a custom SwiftUI button that has a special shape depending on configuration.
A utility function must return a Shape depending on configuration. Since the path/shape is complicated to programme, transformations are used to get variations depending on configuration.
For demonstration purpose, a simplified version of the utility function looks like this:
func shape(i: Int) -> some Shape {
let path = Path()
switch i {
case 0:
return path
case 1:
return path.transform(CGAffineTransform(translationX:0,y:0))
default:
break
}
return path
}
Unfortunately the compiler generate the well known error:
Function declares an opaque return type, but the return statements in its body do not have matching underlying types
I am sure this happens due to the transformation, although it returns a struct
func transform(_ transform: CGAffineTransform) -> TransformedShape<Self>
that conforms to Shape (like Path do):
struct TransformedShape<Content> where Content : Shape
Documentation for Path states that Path conforms to Shape, and this makes me think that I am overlooking something or that this may be a bug in the compiler.
If someone knows a workaround or can see that I am doing something wrong - please let me known.
Thanks.