开发者

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 ???

开发者_如何学Go
NSArray 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]; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜