How to use NSPointArray?
Asked Answered
L

2

6

So I want to use the method appendBezierPathWithPoints:count: in NSBezierPath. But the method requires me to use NSPointArray. The documentary doesn't really talk much about it and all I could get about it is that it's an array of NSPoints and I'm not sure how to do it. I think that it uses the c array mechanism, but I'm not sure.

Thanks.

Lowenstern answered 23/2, 2011 at 12:51 Comment(0)
T
9

Yes, you need a C-style array of points to pass to appendBezierPathWithPoints:count:. For example you might do something like this:

NSPoint pointArray[3];

pointArray[0] = NSMakePoint(0, 0);
pointArray[1] = NSMakePoint(0.5, 0.25);
pointArray[2] = NSMakePoint(1, 1);

[lines appendBezierPathWithPoints:pointArray count:3];

where lines is an instance of NSBezierPath.

In a more complicated case you'll use a variable number of points say.

Tautomerism answered 23/2, 2011 at 13:14 Comment(0)
B
3

If you want to use Objective-C style array, then you have to use NSValue class for this purpose.

NSMutableArray *array = [NSMutableArray array];

CGPoint myPoint;
myPoint.x = 100;
myPoint.y = 200;

[array addObject:[NSValue valueWithPoint:myPoint]];

To retrieve an NSPoint back from the array:

myPoint = [array[0] pointValue];

Hope it helps.

Bondy answered 30/7, 2015 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.