20. November 2016
Adding Floats to Ints without hassle
This extension lets you add Float
, Double
and CGFloat
to an Int
without the need to cast them beforehand.
extension Int {
static func +(lhs: Int, rhs: Float) -> Float {
return Float(lhs) + rhs
}
static func +(lhs: Int, rhs: Double) -> Double {
return Double(lhs) + rhs
}
static func +(lhs: Int, rhs: CGFloat) -> CGFloat {
return CGFloat(lhs) + rhs
}
}