You can only store Objective-C objects in an NSMutableArray
.
One route you can take is to use a standard C array:
unsigned int array_length = ...;
Node** nodes = malloc(sizeof(Node *) * array_length);
Another route is to wrap the structure in an Objective-C object:
@interface NodeWrapper : NSObject {
@public
Node *node;
}
- (id) initWithNode:(Node *) n;
@end
@implementation NodeWrapper
- (id) initWithNode:(Node *) n {
self = [super init];
if(self) {
node = n;
}
return self;
}
- (void) dealloc {
free(node);
[super dealloc];
}
@end
Then, you'd add NodeWrapper
objects to your NSMutableArray
like this:
Node *n = (Node *) malloc(sizeof(Node));
n->AE = @"blah";
NodeWrapper *nw = [[NodeWrapper alloc] initWithNode:n];
[myArray addObject:nw];
[nw release];
To retrieve the Node
from the NodeWrapper
, you'd simply do this:
Node *n = nw->node;
or
Node n = *(nw->node);