Hello!
I'm trying to Make a custom viewModifier which will add a defined number of shape views on a card based on a parameter. To do this, I'm using a VStack which in itself is nested inside a Zstack. But for some reason I get a "Unable to infer complex closure return type; add explicit type to disambiguate" error.
Below is the body function of the viewModifier
import SwiftUI
struct addShape: ViewModifier{
var shapeType: CardShape
var shadingType: Double
var shapeColor: Color
var size: CGSize
var noOfShapes: Int
func body(content: Content) -> some View{
ZStack{
VStack{
ForEach(1..<noOfShapes, id: \.self){
Group{
if (shapeType == .rectangle){
RoundedRectangle(cornerRadius: radiusValue)
.fill(shapeColor)
.opacity(shadingType)
RoundedRectangle(cornerRadius: radiusValue)
.stroke(lineWidth: strokeWidth)
}
else if (shapeType == .oval){
Ellipse()
.fill(shapeColor)
.opacity(shadingType)
Ellipse()
.stroke(lineWidth: strokeWidth)
}
else {
RoundedRectangle(cornerRadius: radiusValue)
.fill(shapeColor)
.opacity(shadingType)
RoundedRectangle(cornerRadius: radiusValue)
.stroke(lineWidth: strokeWidth)
}
}
.frame(width: (size.width)/CGFloat(noOfShapes+1), height: (size.height)/CGFloat(noOfShapes+1), alignment: .center)
.foregroundColor(shapeColor)
}
}
content
}
}
let strokeWidth: CGFloat = 2
let radiusValue: CGFloat = 8
}
Where am I going wrong?