In my program I have two classes: Collector and Entity. Collector stores Entities in NSMutableArray.
@interface Entity : NSObject {
...
}
@interface Collector : NSObject {
NSMutableArray *entities;
uint someInt;
...
}
- (void)addEntity:(Entity*)newEntity; // implemented as [entities addObject:newEntity];
Collectors are also stored in NSMutableArray (let's call it collectors). Then I have such code (something like this):
for (uint i = 0; i < [collectors count]; i++) {
Collector *curCollector = [[collectors objectAtIndex:i] retain];
Entity *curEntity = [[Entity alloc] init];
[curCollector addEntity:curEntity];
[curCollector setSomeInt:50];
[curEntity release];
[curCollector release];
}
After execution of this code part, I have no new entities inside collectors, but someInt value changes correctly. Moreover, when I debug my code, on step before releasing of variables, curCollector contains new entity and has address, same as one of objects inside collectors array, but that object (in collectors array) has no entities.
What am I doing wrong?
P.S.:
During debug I checked all objects - no nils found (especially for entities).
About addObject - all implementation code is [entities addObject:newEntity];
And another interesting thing (to point in in my explanation above) - int value is set correctly (objects of the collectors' array contain someInt == 50).
P.P.S: I've added a line before releasing code parts:
[collectors replaceObjectAtIndex:i withObject:curCollector];
No results!!