NSArray of structures?
Trying to implement the following structure from "c" to use NSArray in objective-c:
In standard-c:
struct structDog{
char *name;
int age;
};
struct structLitter{
struct structDog puppy[10];
};
Then I use malloc to allocate space. But since I am using NSArray.
But in Objective-c I am using NSArray... so ???
开发者_如何学GoNSArray struct structDog *puppy; // <<---this doesn't work
thanks
Assuming that you are trying to do is get your struct
into your NSArray
you need to use NSValue. For instance you can do something like:
NSArray* myArray = [NSArray arrayWithObjects:[NSValue valueWithPointer: myDog],
[NSValue valueWithPointer: myPuppy],
nil];
structDog* dog = (structDog*)[[myArray objectAtIndex:0] pointerValue];
精彩评论