Keep finding similar questions here, but can't find this one
I want to put several objects into an NSMutableArray, and of course be able to retrieve them.
I can put individual strings (First line, Second Line, etc) into the array (as objects), and can see in debugger that they are all being stored - can retrieve them too.
(I don't actually need to put these individual strings in - I only need to put in my "Person" objects. Just thought it might help me to see what does work in terms of moving forward in the NSMutableArray)
Person *aPerson = [[Person alloc] init];
NSMutableArray *myArray = [[NSMutableArray alloc] init];
[myArray addObject:@"First line"];
[myArray addObject:@"Second line"];
[myArray addObject:@"Third line"];
[myArray addObject:@"Fourth line"];
[myArray addObject:@"Fifth line"];
When I put ONE object into the same array, it goes in fine.
aPerson.firstName = @"Jasper"; // Should be sixth
aPerson.lastName = @"John";
[myArray addObject:aPerson];
In the debugger when stopping at above point I see the "Jasper John" info in a Person object in the NSMutableArray .... But when I put another object into that NSMutableArray, it replaces the last object - it's as those I didn't advance through the NSMutableArray.
aPerson.firstName = @"Izzie";// Should be seventh
aPerson.lastName = @"TheKitty";
[myArray addObject:aPerson];
aPerson.firstName = @"Roxie";
aPerson.lastName = @"The Pup";
[myArray addObject:aPerson]; // Should be eighth
When stopping at above point, I just get "Roxie The Pup" for all 3 objects in the NSMutable Array - though my original 5 strings are still filling up the buckets at the beginning.