This is my current way of converting a CGFloat to String in Swift:
let x:Float = Float(CGFloat)
let y:Int = Int(x)
let z:String = String(y)
Is there a more efficient way of doing this?
This is my current way of converting a CGFloat to String in Swift:
let x:Float = Float(CGFloat)
let y:Int = Int(x)
let z:String = String(y)
Is there a more efficient way of doing this?
The fast way:
The better way, because it takes care on locales:
You can use string interpolation:
Or technically, you can use the printable nature of CGFloat directly:
The
description
property comes from it implementing thePrintable
protocol which is what makes string interpolation possible.