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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to