gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:07:31 36 4
gpt4 key购买 nike

我刚刚开始自学用 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/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com