CGPoint:无法调用非函数类型`[Float]`的值

CGPoint: Cannot call value of non-function type `[Float]`

我正在开发一个应用程序,它应该在触摸时在触摸的位置绘制点,当我有 2 个或更多点时,它应该连接这些点并填充新对象。

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if(draw == true){

        for touch in touches {
            let location = touch.location(in: view)

            pointsX.append(Float(location.x))
            pointsY.append(Float(location.y))

            let touchIndicator = UIView(frame: CGRect(x: location.x - 10, y: location.y - 10, width: 20, height: 20))
            touchIndicator.alpha = 0.8
            touchIndicator.backgroundColor = UIColor.red
            touchIndicator.layer.cornerRadius = 10
            self.view.addSubview(touchIndicator)
            touchIndicators.append(touchIndicator)
        }

    }
}

每次我都将x和y坐标以float类型保存到数组pointX和pointY中。但是当我需要在两点之间画一条线时,它告诉我一个错误 Cannot call value of non-function type [Float].

let squarePath = UIBezierPath()

    squarePath.move(to: CGPoint(x: pointsX(0), y: pointsY(0)))

    squarePath.addLine(to: CGPoint(x: 200, y: 100))
    squarePath.addLine(to: CGPoint(x: 200, y: 200))



    squarePath.close()

    let square = CAShapeLayer()
    square.path = squarePath.cgPath
    square.fillColor = UIColor.red.cgColor
    self.view.layer.addSublayer(square)

有没有其他解决办法,我的CGPoints在哪里可以保存?

如果我能求一个代码,那对我来说会更容易,我的英语不好,谢谢。

Swift用方括号索引数组,你用的是括号

squarePath.move(to: CGPoint(x: pointsX[0], y: pointsY[0]))

我在这里创建了一个函数,它允许您将 CGPoint 转换为 double

 func convertCgPointToDoule(location: CGPoint) -> Double {
        let position = sprite.position.y
        return return position - location.y

    }