You may create a category on NSValue
in order to add the valueWithCGPoint:
and CGPointValue
methods to Cocoa.
#if ! TARGET_OS_IPHONE
@interface NSValue (MyCGPointAddition)
+ (NSValue *)valueWithCGPoint:(CGPoint)point;
- (CGPoint)CGPointValue;
@end
#endif
#if ! TARGET_OS_IPHONE
@implementation NSValue (MyCGPointAddition)
+ (NSValue *)valueWithCGPoint:(CGPoint)point {
return [self valueWithPoint:NSPointFromCGPoint(point)];
}
- (CGPoint)CGPointValue {
return NSPointToCGPoint([self pointValue]);
}
@end
#endif
Or you may use valueWithBytes:objCType:
and getValue:
.
CGPoint point = {10, 10};
NSValue *value = [NSValue valueWithBytes:&point objCType:@encode(CGPoint)];
// ...
[value getValue:&point];