Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

scalar

simd

I've just started teaching myself to write in Swift. I'm currently trying to rotate an image when I press a button (just practicing with really simple stuff) and Xcode has thrown two errors at me:

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

String interpolation can only appear inside a string literal

I've searched around the web a bit for info on SIMD but I couldn't understand any of it! Can someone break it down for a clueless newbie? This is my code so far. Some of it is from online tutorials, some from Xcode's suggestions, some I just guessed:

@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
    })

}
like image 923
SwiftBeginner Avatar asked Sep 14 '25 05:09

SwiftBeginner


1 Answers

The string interpolation error results from your use of \(). Just delete the backslashes.

Data types conforming to the SIMD protocol allow the compiler to generate faster code using single-instruction multiple-data instructions (such as SSE and AVX on Intel processors). Assuming rotationDegree is declared with a usual floating-point type, maybe the error results from the incorrect use of the backslash.

like image 175
ahooper Avatar answered Sep 15 '25 20:09

ahooper