|
How do I add structures to an array of objects — specifically, a NSMutableArray of typedef struct?
typedef struct {
int messageA;
int messageB;
int messageC;
} packetStruct;
packetStruct msg;
msg.messageA = 0;
msg.messageB = 1;
msg.messageC = 2;
NSMutableArray* packetArray = [[NSMutableArray alloc] init];
[packetArray addObject:[NSValue valueWithBytes:&msg objCType:@encode(packetStruct)]];
How do I retrieve the values of the first structure from this array of objects?
NSValue *value = [packetArray objectAtIndex:0];
[value getValue:&msg];
int x = msg.messageA;
int y = msg.messageB;
int z = msg.messageC;
Here's another way.
[[packetArray objectAtIndex:0] getValue:&msg];
x = msg.messageA;
y = msg.messageB;
z = msg.messageC;
How do I retrieve the values of all of the structures from this array of objects?
for (NSValue* packet in packetArray) {
[packet getValue:&msg];
x = msg.messageA;
y = msg.messageB;
z = msg.messageC;
}
|
|