How to use NSMutable Array with Struct - Xcode
I am using an NSMutableArray to store a struct with data. So I am having problem to get values from NSMutableArray/Struct. Take a look in my code below: ....
{
NSMutableArray * arrGameControl;
arrGameControl = [NSMutableArray array];
//Struct definition
typedef struct {
int player;
int armaCod;
int armaID;
int armaIndex;
int armaIndexStatus;
int armaIdOrientacao;
} sttDataGame;
//Define the valDados and put values inside struct
sttDataGame valDados;
valDados.armaCod=30;
valDados.armaID=30;
valDados.armaIdOrientacao=30;
valDados.armaIndex=30;
valDados.armaIndexStatus=30;
valDados.player=30;
NSLog(@"Valor Inicial : %d",
valDados.armaCod);
//Add rows in my NSMutableArray using struct data
[ arrGameControl addObject: [NSValue value:&valDados withObjCType:@encode(struct sttDataGame)]];
//Reset struct values
valDados.armaCod=0;
//Here I have a problem
[[ arrGameControl objectAtIndex:0] getValue:&valDados];
NSLog(@"%d",valDados开发者_高级运维.armaCod);
}
..............
What's wrong in this code? Thanks for your attention.
精彩评论