Reputation: 45128
I have a method like this:
- (CGPoint) _convertCGPointCT2UIKit:(CGPoint)ctPoint{
CGPoint uikitPoint = CGPointMake(ctPoint.x + INITIAL_HORIZ_OFFSET,
self.bounds.size.height - ctPoint.y - INITIAL_VERT_OFFSET);
return uikitPoint;
}
Is there any way I can make this a macro? I tried this but I get errors like "; expected before )" and so on.
#define CGPointUIKit2CT(p) CGPointMake(p.x - INITIAL_HORIZ_OFFSET, self.bounds.size.height - p.y - INITIAL_VERT_OFFSET);
thanks in advance.
Ignacio
Upvotes: 2
Views: 1715
Reputation: 43452
While there may be reasons to avoid method dispatch for something like this, there is no reason to do it as a macro instead of a static inline function:
static inline
CGPoint CGPointUIKit2CT(UIView *self, CGPoint ctPoint) {
CGPoint uikitPoint = CGPointMake(ctPoint.x + INITIAL_HORIZ_OFFSET,
self.bounds.size.height - ctPoint.y - INITIAL_VERT_OFFSET);'
return uikitPoint;
}
That will compile out to the same thing as a macro, but will provide better debugging and profiling information.
Upvotes: 2
Reputation: 4924
A couple of rules of thumb to guide you:
Here's my answer:
#define CGPointUIKit2CT(p) CGPointMake(((p).x) - INITIAL_HORIZ_OFFSET, self.bounds.size.height - ((p).y) - INITIAL_VERT_OFFSET)
Upvotes: 5