The problem here is to do with pointers. When you modify the self.whatever you modify that for everything that is pointing to the same thing.
Consider the following
Code:
for (int i = 0; i < 3; i++) {
self.stringProperty = [NSString stringWithFormat@"number %i", i];
[self.myMutableArray addObject:self.stringProperty];
}
If we print the contents of this array it will print
Code:
number 2
number 2
number 2
Why is that? Because when you add self.stringProperty to the array you add a pointer to that object, not a copy of that object. So the next iteration of the loop you go and you change the actual value meaning that the value is changed for everyone that is pointing to the actual value.
Consider instead
Code:
for (int i = 0; i < 3; i++) {
NSString *localVariableString = [NSString stringWithFormat@"number %i", i];
[self.myMutableArray addObject:localVariableString];
}
If we print the contents of this array it will print
Code:
number 0
number 1
number 2
Every time we run the loop we create a brand new instance and add that instance to the array rather than re-using the pointer.
There's a fella on here - Brian Slick. He has a really good tutorial on properties in his signature, have a read of that.