I have code similar to this
if (count == 0)
{
[array1 addObject:@"No Items"];
}
else
{
int x;
for (x = 0;x <= count; x++)
{
[array1 addObject:[itemsArray objectAtIndex:x];
NSLog(@"%@",array1);
}
}
itemsArray has numbers in it (0-40). My expected result is:
- 1
- 2
- 3
- …
However it actually does:
- 1
- 1,2
- 1,2,3
- 1,2,3,4
- 1,2,3,4,5
- …
Why does this happen? If possible, I’d also like to ask for an example to use fast enumeration for this situation (if it suits for this).
Thanks in advance.
You are
NSLoging the whole array, not the current index of array1. What you are seeing logged is what you’ve coded – to log what you are expecting, changeNSLog(@"%@",array1);toNSLog(@"%@",[array1 objectAtIndex:x]);To confirm add the following after your assignment loop: