1
I’m facing a problem that a property is getting nil unexplained.
NSMutableArray * lojas = [[NSMutableArray alloc] init];
for (int x = 0; x < lojaResultado.count; x++) {
NSDictionary * listaAtributos = [lojaResultado objectAtIndex: x];
Loja * loja = [[Loja alloc] init];
NSMutableArray * produtosLista = [[NSMutableArray alloc] init];
[loja setName: [listAtributos objectForKey: @"Loja"]];
NSArray * produtosResultado = [[NSArray alloc] initWithArray: [listaAtributos objectForKey: @"Produtos"]];
for(int y = 0; y < produtosResultado.count; y++){
NSDictionary * produtoAtributos = [produtosResultado objectAtIndex:y];
Produto * produto = [[Produto alloc] init];
[produto setNome: [produtoAtributos objectForKey:@"Nome"]];
getNumber = [produtoAtributos objectForKey: @"Tipo"];
[produto setTipo: [getNumber intValue]];
getNumber = [produtoAtributos objectForKey: @"Tamanho"];
[produto setTamanho: [getNumber intValue]];
[produtosLista addObject: produto];
}
loja.produtos = produtosLista;
[lojas addObject: loja];
}
At this time [lojas addObject: loja]; the property loja.produtos is still with the list, but after it will do the second "loop" in the property loop loja.produtos stays nil.
Additional information:
Property in class:
@property (strong, nonatomic) NSMutableArray * list;
The variable getNumber is the type NSDecimalNumber.
Version Xcode: 6.1.1
Version iOS SDK: 8.1
When you add
tiresinprodutosLista, shouldn’t addproduto? Where does that come from remove?– Paulo Rodrigues
@Paulorodrigues Yes, it is
produtowas an error at the time that replaces some variable names for better understanding. I’ve edited.– Gian
small doubt, the property is even nil or an empty array?
– DaSilva
@Dasilva the property itself is
nil, the moment I add it to the array it is normal there, then it isnil. I found the solution just below.– Gian