1

I'm trying to have a function return different type of Shape based on a switch statement. Here is the code... Thanks Function declares an opaque return type, but the return statements in its body do not have matching underlying types. The return functions

The Code in the images:

func getShape(_ card: SetModel.Card) -> some Shape {
        switch card.shape {
        case .oval:
            return ovalShape()
        case .dimond:
            return dimondShape()
        case .squiggle:
            return squiggleShape()
        }
    }

struct ovalShape: Shape {
    func path(in rect: CGRect) -> Path {
        let path = Path(
            roundedRect: CGRect(x: rect.midX - ((rect.width * 2.5) / 2),
                                y: rect.midY - (rect.width / 2),
                                width: rect.width * 2.5,
                                height: rect.width),
            cornerRadius: 200)
        return path
    }
}

struct dimondShape: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()
        let startPoint = CGPoint(x: rect.midX, y: rect.midY - (rect.width / 5))
        let leftMidPoint = CGPoint(x: rect.minX, y: rect.midY)
        let bottomPoint = CGPoint(x: rect.midX, y: rect.midY + (rect.width / 5))
        let rightMidPoint = CGPoint(x: rect.maxX, y: rect.midY)
        
        path.move(to: startPoint)
        path.addLine(to: leftMidPoint)
        path.addLine(to: bottomPoint)
        path.addLine(to: rightMidPoint)
        
        return path
    }
}
KBucevski
  • 21
  • 4

0 Answers0