NSMutable Array always adding the same pointer
The following code should add different objects to an NSMutableArray however it adds the same object each time:-
for(int i =0; i < [results count];i++)
{
Reservation *r = [[Reservation alloc] init];
NSDictionary *dict = [results objectAtIndex: i];
r.resId = [dict objectForKey:@"reservationrequest_id"];
r.driver = [dict objectForKey:@"driver_name"];
r.vehicle = [dict objectForKey:@"billing_registration"];
r.startDate = [dict objectForKey:@"hire_from_date"];
r.endDate = [dict objectForKey:@"hire_to_date"];
r.status = [dict objectForKey:@"status_t开发者_开发技巧ype"];
[self.bookingsObjectArray addObject:r];
[r release];
r = nil;
}
I have exactly the same code that works fine in another part of my app it just uses a Groups class instead of Reservation.
When debugging the code I found that when it does [r release]; 'r' is greyed out but still keeps the same pointer. When it goes back to Reservation *r = [[Reservation alloc] init]; 'r' has the same pointer as last time.
Any ideas what might be causing the problem? Thanks in advance.
Chris
精彩评论