Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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_type"];

        [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

share|improve this question
1  
Have you overwritten the [Reservation alloc] method? What does the init method of Reservation look like? –  mrueg Jun 15 '11 at 10:07
    
Hi mrueg, Thanks for your reply, it helped me figure out my problem. –  user799306 Jun 15 '11 at 10:29
    
In that case, please upvote my comment :) –  mrueg Jun 15 '11 at 10:37
    
problem seems to be with allocating Reservation *r = [[Reservation alloc] init]; every time. –  ajay Jun 15 '11 at 12:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.