I've searched other questions and can't seem to find a similar problem. Either I am something completely wrong or I am blind. But here goes the code:
@autoreleasepool {
NSMutableString *sense = [[NSMutableString alloc] init];
NSMutableArray *senses = [[NSMutableArray alloc] init];
....... other code which initializes rL and count/length .......
for (index=0;index<count;index++) {
for (j=0;j<length;j++) {
c = [rL characterAtIndex:j];
switch (c) {
case '.':
[senses addObject:sense];
[sense setString:@""];
break;
default:
[sense appendFormat:@"%c",c];
break;
}
}
}
}
When I do this, and iterate, in debug mode, I see that all objects in senses are same as whatever the last value of sense was.
what am I doing wrong?
"sense" is always the same object. It is a mutable string, so the contents can change, but it is always the same object. So senses will contain that single object, multiple times. You could instead use
[senses addObject:[sense copy]];