What\'s the easiest way to create an array of structs in Cocoa?
If you want to use an NSArray you'll need to box up your structs. You can use the NSValue class to encode them.
Something like this to encode:
struct foo {
int bar;
};
struct foo foobar;
foobar.bar = 3;
NSValue *boxedFoobar = [NSValue valueWithBytes:&foobar objCType:@encode(struct foo)];
And then to get it back out:
struct foo newFoobar;
if (strcmp([boxedFoobar objCType], @encode(struct foo)) == 0)
[boxedFoobar getValue:&newFoobar];