请考虑以下内容:
struct Entry {
let points: [CGPoint]
func squeezePoints(_ multiplier: CGFloat) -> [CGPoint]{
return points.map{$0.x * multiplier}
}
}
由于错误而无法编译代码:Cannot convert value of type 'CGFloat' to closure result type 'CGPoint'
答案 0 :(得分:3)
您试图映射到CGFloat
,但是将函数的返回类型声明为[CGPoint]
。如果要乘以每个点的x坐标,请修改函数以映射到CGPoint
并保持y
不变。
func squeezePoints(_ multiplier: CGFloat) -> [CGPoint]{
return points.map{CGPoint(x: $0.x * multiplier, y: $0.y)}
}