Re: getting a point from an array of NSValue CGPoints
Re: getting a point from an array of NSValue CGPoints
- Subject: Re: getting a point from an array of NSValue CGPoints
- From: David Duncan <email@hidden>
- Date: Fri, 22 May 2009 12:54:39 -0700
On May 22, 2009, at 12:45 PM, Jeff Decker wrote:
Thank you for your help. I have a mutable array filled with
NSValues which are CGPoints. I want to unpack them one by one while
adding them to a CGContextAddLineToPoint rect. Here is my terrible
attempt (most of the code is from the Stanford class on iTunes -
which I'm really enjoying!):
for (int i = 0; i < [myPolygon numberOfSides]; i++){
NSValue *value = [arrayOfPoints objectAtIndex:i]; //yikes!!!
CGPoint point = [value CGPointValue]; //yikes!!!
NSLog(@"points plotted: %f, %f", point.x, point.y);
CGContextAddLineToPoint (context, point.x, point.y);
}
I'm not certain why the "Yikes!" here, but it looks like your doing
things just fine to me :). The only thing you might consider is using
the for-in syntax instead ala
for(NSValue *value in myPolygon) {
CGPoint point = [value CGPointValue];
...
}
But if you want to avoid packing & unpacking, then you might also look
into the CGPath APIs that allow you to do the same kinds of
construction that your doing and provides a data type that you can add
to the context and then do all the typical path stuff with.
--
David Duncan
Apple DTS Animation and Printing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden