请考虑以下:
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'
您正在尝试将其映射到CGFloat
,但将函数的返回类型声明为[CGPoint]
。如果要乘以每个点的X坐标,请修改您的功能以映射到CGPoint
并保持y
未修改。
func squeezePoints(_ multiplier: CGFloat) -> [CGPoint]{
return points.map{CGPoint(x: $0.x * multiplier, y: $0.y)}
}