swift - 在 '*' 上引用运算符函数 'SIMD' 要求 '_.Scalar' 符合 'FloatingPoint'

标签 swift simd scalar

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

Referencing operator function '*' on 'SIMD' requires that '_.Scalar' conform to 'FloatingPoint'

String interpolation can only appear inside a string literal

我在网上搜索了一些有关 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
    })

}

最佳答案

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

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

关于swift - 在 '*' 上引用运算符函数 'SIMD' 要求 '_.Scalar' 符合 'FloatingPoint',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59025756/

相关文章:

swift - 刷新步进值

swift - 验证按钮单击并更改 Controller View iOS

delphi - 如何使用扩展数组进行SIMD?

visual-c++ - visual studio编译代码时arch参数如何使用?

r - 将一个矩阵与一组标量相乘

objective-c - 使用网桥从 .framework 导入文件时出错

c++ - 使用 SSE 的矩阵乘法

arrays - 作业中的 Perl 'context'

perl - 这在 perl $variable_one{$variable_two} 中是什么意思,它叫什么?

ios - 设置 UITextField 的最大 int 值(不是字符数)