Usually the best solution is to save the type and use CGFloat , even in Swift. This is because CGFloat has different sizes on 32-bit and 64-bit machines.
The as keyword can only be used for a dynamic cast (for subclasses), for example
class A { } class B : A { } var a: A = B() var b: B = a as B
However, Double , Int , Float , etc. are not subclasses of each other, so for "cast" you need to create a new instance, for example
var d: Double = 2.0 var f: Float = Float(d) //this is an initialiser call, not a cast var i: Int = Int(d) //this is an initialiser call, not a cast
Sulthan Jun 10 '14 at 18:04 2014-06-10 18:04
source share