Reputation: 668
I'm having a brain cramp this afternoon. This should be easy.
I did read the docs.
It's easy to convert single instances of Float <> CGFloat but I'm looking for a fast method to cast a LARGE array > 500,000 elements of [Float] to [CGFloat].
var sphereRadiusFloat:[Float] = [0.0,1.0,2.0]
var sphereRadiusCGFloat:[CGFloat] = []
sphereRadiusCGFloat = sphereRadiusFloat as CGFloat
The error is
CGFloat is not convertible to [CGFloat]
I also tried
sphereRadiusCGFloat = CGFloat(sphereRadiusFloat)
which gives error
Could not find an overload operator for 'init' that accepts supplied arguments.
Upvotes: 1
Views: 2459
Reputation: 236370
You can use map to do it as follow:
sphereRadiusCGFloat = sphereRadiusFloat.map{CGFloat($0)}
Upvotes: 4