How to put struct into array in Objective-C
As a lot of iphone libraries (Cocos2D, Chipmunk...) use structures for basic elements, you sometimes need to use dynamic arrays. If you do not want to wrap C++ code in your Objective-C sources (using vectors or other STL container) you can use a trick that helps storing data structure into basic Objective-C arrays. Example with vertex of a circle in Cocos2D :
NSMutableSet *circleVertex = [[NSMutableSet alloc] init];
for(float theta = 0; theta < 2*M_PI; theta += M_PI/8) {
float x = circle.center.x + circle.radius * cos(theta);
float y = circle.center.y + circle.radius * sin(theta);
CGPoint p = ccp(x,y);
NSValue *point = [NSValue value:&p withObjCType:@encode(CGPoint)];
[circleVertex addObject:point];
}
For getting the value :
for(NSValue *val in circleVertex) {
CGPoint p;
[val getValue:&p];
}













