Re: NSArray usage question.
Re: NSArray usage question.
- Subject: Re: NSArray usage question.
- From: Sherm Pendley <email@hidden>
- Date: Fri, 6 May 2005 16:40:31 -0400
On May 6, 2005, at 3:24 PM, Brian O'Brien wrote:
Is this the correct way to build and use an NSArray?
No. :-(
NSPoint ptArray[plist->getNPolys()];
CPoint p;
for (i=0; i < plist->getNPolys(); ++i)
{
p = plist->getPoint(i);
ptArray[i].x = p.x;
ptArray[i].y = p.y;
}
NSArray *pts = [NSArray arrayWithObjects:ptArray count:i];
Okay, first point: +arrayWithObjects:count: takes a C array of
objects, but you're passing it a C array of NSPoint structs. As Rocky
J. Squirrel said, "aww, that trick never works."
NSBezierPath *path = [NSBezierPath bezierPath];
[path appendBezierPathWithPoints:pts count:i];
But it turns out to be unnecessary anyway, if this is all you're
doing with it. -appendBezierPathWithPoints:count: takes a C array of
NSPoint structs. So all you really need to do is get rid of the
intermediate NSArray altogether, and simply pass ptArray directly:
[path appendBezierPathWithPoints:ptArray count:i];
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden