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 nil
before the loop starts:
NSLog(@"%@", self.categoriasArray); // This will output null
for (int i = 0; i < [categories count]; i++) {
// ...
}
What you should understand is that synthesizing the property categoriasArray
doesn'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):
self.categoriasArray = [[NSMutableArray alloc] init];
The other possibility is that categories
is itself nil
or doesn't contain any items. To check that, add NSLog
s before the loop:
NSLog(@"%@", self.categoriasArray);
NSLog(@"%@", categories);
NSLog(@"%d", [categories count]);
for (int i = 0; i < [categories count]; i++) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With