@implementation Level
@synthesize doors, rooms;
- (id) init
{
self = [super init];
if (self != nil) {
rooms = [[NSMutableArray alloc] init];
doors = [[NSMutableArray alloc] init];
}
return self;
}
- (void)generate{
int room_count = 2;
Room *room;
for (int i=0; i<room_count; i++) {
room = [[Room alloc] init];
[room generate_Doors];
[self.rooms addObject:room];
[room release];
}
for (int i=0; i<[rooms count]; i++) {
Room *r=[rooms objectAtIndex:i];
//After this point rooms is invalid
int l=[[r doors] count];
for (int j=0; j<l; j++) {
Door *d=[[[rooms objectAtIndex:i] doors] objectAtIndex:j];
[self.doors addObject:d];
}
}
}
这是我在调试器中看到的
替代文字 http://img163.imageshack.us/img163/8090/20091117174111.png