iOS Sorting with bubble sort but last row not sorted
===

I've completed sorting dates with bubble sort. However, halfway through testing I've noticed that it does not sort the last row. Can anyone help? :( it's very important to me as it's the basis of what I need to do my codes for the sorting:

    NSInteger count = [sortingArray count];
            for(int a = 0 ; a < count; a++) {
                for(int b = a+1 ; b < count; b++) {
                NSDictionary *dic = [items objectAtIndex:a];
                NSDictionary *dic2 = [items objectAtIndex:b];
                NSString *dateString = [dic valueForKey:@"date"];
                NSString *dateString2 = [dic2 valueForKey:@"date"];
                //NSLog(@"DATE: %@", dateString);   //date is the string representation.
                    
                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
                [dateFormatter setDateFormat:@"dd/MM/yyyy"];
                NSDate *endDate = [dateFormatter dateFromString:dateString];
                NSDate *endDate2 = [dateFormatter dateFromString:dateString2];
                
                NSDate *currDate = [NSDate date];
                NSString *startDateString = [dateFormatter stringFromDate:currDate];
                NSDate *startDate = [dateFormatter dateFromString:startDateString];
                [dateFormatter release];
                
                NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
                NSDateComponents *comp = [gregorianCalendar components: NSDayCalendarUnit 
                                                              fromDate:startDate 
                                                                toDate:endDate
                                                               options:0];
                
                
                NSDateComponents *comp2 = [gregorianCalendar components: NSDayCalendarUnit 
                                                               fromDate:startDate
                                                                 toDate:endDate2
                                                                options:0];
                [gregorianCalendar release];
                
                NSInteger compareDay = [comp day];    
                NSInteger compareDay2 = [comp2 day];  
                NSString *dayString = [NSString stringWithFormat:@"%d", compareDay];
                    NSString *dayString2 = [NSString stringWithFormat:@"%d", compareDay2];
                NSLog(@"string 1%@", dayString); 
                    NSLog(@"string 2 ----%@", dayString2); 
                
                if (compareDay > compareDay2){
                    [sortingArray exchangeObjectAtIndex:a withObjectAtIndex:b];
                } 
            }    //b loop
        }   //a loop
            NSInteger counterIndex = [sortingArray count];
            for(int c = 0; c < counterIndex ; c++) {
                [temp addObject:[sortingArray objectAtIndex:c]];
            }        

[how it looks like for now][1] Please help many many manyyyyy thanks!!


  [1]: https://995752eb-a-62cb3a1a-s-sites.googlegroups.com/site/1004606hmp/photo.jpeg?attachauth=ANoY7crIQ0EBA0sI3EiZmO-2qizMwsm8PGPJ9zEhcb094lJAn0-zSgRzXDNJfNE06wSo-bN-qw11_rd-xZbv7tKzXnRT_tmCjg2-o1gqEJKYO3e5n2R0wGIfYhFNF7JCP5TvIunYNzu5NEkexgOnVrL5L8TmO1ECzbt23zKTelJmKRlzARLgBz9I1_pI2_niHKIzj8GySbNrFabD4_pt0I5L-wM-Rs6VXg==&attredirects=0