I'm trying to create some simple funcs to create different shapes (diamond, rectangle and capsule) with different colors and different shading (filled, stroked and striped). To abstract some of the repetition away I've tried to pass the shape but get the dreaded "Protocol 'Shape' can only be used as a generic constraint because it has Self or associated type requirements". I've also tried passing an Int and using a Switch statement to recreate the shape in function but that has also not worked.
This function works for any color, but only one shape:
func stripedSymbol (_ solidColor: Color) -> some View {
let shape = Diamond()
return ZStack {
shape.fill(gradientFill(solidColor))
shape.stroke(solidColor)
}
}
Would like to be able to call the function with color AND shape (either directly or encoded in Int or enum) something like this:
func stripedSymbol (_ solidColor: Color, shape: Shape) -> some View {
return ZStack {
shape.fill(gradientFill(solidColor))
shape.stroke(solidColor)
}
}
Any suggestions?