I’m trying to add objects to NSMutableArray (categoriasArray), but its not done by the iterator:
@synthesize categoriasArray;
for (int i = 0; i < [categories count]; i++) {
categoria *cat = [[categoria alloc] initWithDictionary:[categories objectAtIndex:i]];
[self.categoriasArray addObject:cat];
cat=nil;
}
After the for iterator, categoriasArray has 0 objects.
Many thanks
Check that the array is not
nilbefore the loop starts:What you should understand is that synthesizing the property
categoriasArraydoesn’t initialize it, it just generates the setter and the getter methods. So, to solve your problem, initialize the array before the loop, (or in the init method of your class):The other possibility is that
categoriesis itselfnilor doesn’t contain any items. To check that, addNSLogs before the loop: