I´m using this method to initialize an nsmutablearray
- (void)getAllContacts
{
Contact *contact = [[Contact alloc] init];
self.allContacts = [[NSMutableArray alloc] init];
int i=0;
for (i=0; i<5; i++)
{
contact.nome = [[NSString alloc] initWithFormat:@"Bruno %d", i];
[self.allContacts insertObject:contact atIndex:i];
}
}
Pretty straightforward! But right after, i do a for to print it´s elements like:
for (int i=0; i<[self.allContacts count]; i++)
{
Contact *c = [self.allContacts objectAtIndex:i];
NSLog(@"i=%d\nNome:%@", i, c.nome);
}
And it will show me 5 times the last element “Bruno 4”. It doesn´t start from 0 and increments. What should i do to start from 0?
Try this:
and please take a look at: Memoy Management