引用'SIMD'上的运算符'*'要求'_.Scalar'符合'FloatingPoint'

时间:2019-11-25 05:34:02

标签: swift simd scalar

我刚刚开始自学用Swift写作。我目前正在尝试按下按钮时旋转图像(只是练习非常简单的东西),而Xcode向我抛出了两个错误:

“在'SIMD'上引用运算符'*'要求'_.Scalar'符合'FloatingPoint'” “字符串插值只能出现在字符串文字中”

我已经在网上搜索了一些有关SIMD的信息,但我听不懂!有人可以将它分解为无知的新手吗?到目前为止,这是我的代码。其中一些来自在线教程,一些来自Xcode的建议,一些我刚刚猜到的:

@IBAction func spinButton(_ sender: Any) {

        if self.rotationDegree != 360 {

            self.rotationDegree += 1
            //to increase the rotation by 1 degree

        }

        else {

            self.rotationDegree -= 360
            //to put the rotation back to 0 degrees

        }


     UIView.animate(withDuration: 1.0, animations: {

        self.vortex2.transform = CGAffineTransform(rotationAngle: \(rotationDegree) * .pi / \(rotationDegree))
        //this is where both error messages appear

    })


}

1 个答案:

答案 0 :(得分:1)

字符串内插错误是由您使用\()引起的。只需删除反斜杠即可。

符合SIMD协议的数据类型允许编译器使用单指令多数据指令(例如Intel处理器上的SSE和AVX)生成更快的代码。假设rotationDegree声明为普通的浮点类型,则错误可能是由于反斜杠的错误使用引起的。