Re: NSArray usage question.
Re: NSArray usage question.
- Subject: Re: NSArray usage question.
- From: Shawn Erickson <email@hidden>
- Date: Fri, 6 May 2005 13:58:06 -0700
On May 6, 2005, at 12:24 PM, Brian O'Brien wrote:
Is this the correct way to build and use an NSArray?
No. :-)
NSPoint ptArray[plist->getNPolys()];
[snip]
NSArray *pts = [NSArray arrayWithObjects:ptArray count:i];
This above is attempting to add NSPoint _structures_ to an NSArray
which is expecting _objects_ (minimally things that implemented the
NSObject protocol [1], well at least retain, release, and likely hash
and isEqual: if not a few others).
This won't work.
[path appendBezierPathWithPoints:pts count:i];
Also the above wants a standard C array of points but you are
attempting to give it a NSArray instance instead. In this case no
need to bother with NSArray at all, just pass in your ptArray. In
other words...
int ptCount = plist->getNPolys();
NSPoint ptArray[ptCount];
for (i=0; i < ptCount; ++i)
{
CPoint p = plist->getPoint(i);
ptArray[i].x = p.x;
ptArray[i].y = p.y;
}
NSBezierPath *path = [NSBezierPath bezierPath];
[path appendBezierPathWithPoints:ptArray count:ptCount];
-Shawn
[1] <http://developer.apple.com/documentation/Cocoa/Reference/
Foundation/ObjC_classic/Protocols/NSObject.html>
_______________________________________________
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