4

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

}
pkamb
  • 33,281
  • 23
  • 160
  • 191
SwiftBeginner
  • 49
  • 1
  • 2

1 Answers1

2

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.

ahooper
  • 46
  • 1
  • 5