0

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)
    }
}
Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
  • Your extension looks fine. What you mean you can't use it? let myRect = CGRectMake(0, 0, 10, 10).CGRectMultiply(2) //{x 0 y 0 w 20 h 20} – Leo Dabus Apr 18 '15 at 19:14
  • @LeonardoSavioDabus but, thats not how we call a inline function, right? We call the CGRectMake function directly, but this CGRectMultiply function I created, requires a CGRect object. – Ramaraj T Apr 18 '15 at 19:27
  • That's how you call the extension you need a CGRect to multiply (self) – Leo Dabus Apr 18 '15 at 19:36
  • 1
    fromRect = rect.CGRectMultiply(UIScreen.mainScreen().scale) – Leo Dabus Apr 18 '15 at 19:43

0 Answers0