I have used the inline functions in Objective-C, but I can't use the same syntax in Swift. This is how I did it in Objective-C.
static inline CGRect CGRectMultiply(CGRect rect, CGFloat factor)
{
return CGRectMake(rect.origin.x*factor, rect.origin.y*factor, rect.size.width*factor, rect.size.height*factor);
}
This is how I call this,
fromRect = CGRectMultiply(rect, [UIScreen mainScreen].scale);
Even the CGRect
has inline functions like CGRectMake
in Swift, but I can't find the syntax for creating one here. I tried this one in Swift, but cannot use this as a inline function like CGRectMake
extension CGRect {
func CGRectMultiply(factor: CGFloat) -> CGRect {
return CGRect(x: origin.x*factor, y: origin.y*factor, width: size.width*factor, height: size.height*factor)
}
}