Tuesday, April 20, 2010

Getting back into Objective-C Programming

Thanks to Stanfords C193P course.
Some things I've found along the way:
FYI, because of the black text you'll need to copy/paste to see the entire codeblock
Convert a NSArray to C array:

NSArray *pointsArray = [PolyShape pointsForPolygonInRect:rect numberOfSides:[polygon numberOfSides]];

//count the number of objects in the array and set a matching integer

int i;

i=[pointsArray count];

//setup our C array to match the number of objects in the pointsArray...

CGPoint thePointArray[i];

//for each object in the pointsArray, set a CGPoint value, add it to the C-Array (thePointArray) in it's matching index

for (id object in pointsArray) {

CGPoint thePoint = [object CGPointValue];

i--;

thePointArray[i] = CGPointMake(thePoint.x, thePoint.y);

}

No comments:

Post a Comment