Casting an Int to a Float

To cast an Int to a Float:

let someInt: Int = 3
let someFloat: CGFloat = CGFloat(someInt)

This is useful if you’d like to generate a random float:

let randomY = CGFloat(arc4random() % 1000) / 1000
 

swiftfreak

 

Leave a Reply

Your email address will not be published. Required fields are marked *